NerdsAndCompany\Schematic\Services\ElementIndexSettings::import PHP Method

import() public method

public import ( array $settingDefinitions, boolean $force = false ) : Result
$settingDefinitions array
$force boolean
return Result
    public function import(array $settingDefinitions, $force = false)
    {
        Craft::log(Craft::t('Importing Element Index Settings'));
        foreach ($settingDefinitions as $elementType => $settings) {
            if (!$this->getElementIndexesService()->saveSettings($elementType, $settings)) {
                $this->addError(Craft::t('Element Index Settings for {elementType} could not be installed', ['elementType' => $elementType]));
            }
        }
        return $this->getResultModel();
    }

Usage Example

 /**
  * Test default import functionality.
  *
  * @covers ::import
  */
 public function testImport()
 {
     $data = $this->getElementIndexSettingsData();
     $mockElementIndexesService = $this->getMockElementIndexesService($data);
     $this->setComponent(Craft::app(), 'elementIndexes', $mockElementIndexesService);
     $import = $this->schematicElementIndexSettingsService->import($data);
     $this->assertTrue($import instanceof Result);
     $this->assertTrue($import->hasErrors());
 }