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

export() public method

public export ( array $data = [] ) : array
$data array
return array
    public function export(array $data = [])
    {
        Craft::log(Craft::t('Exporting Element Index Settings'));
        $settingDefinitions = [];
        // Get all element types
        $elementTypes = $this->getElementsService()->getAllElementTypes();
        // Loop through element types
        foreach ($elementTypes as $elementType) {
            // Get element type name
            $elementTypeName = preg_replace('/^Craft\\\\(.*?)ElementType$/', '$1', get_class($elementType));
            // Get existing settings for element type
            $settings = $this->getElementIndexesService()->getSettings($elementTypeName);
            // If there are settings, export
            if (is_array($settings)) {
                // Group by element type and add to definitions
                $settingDefinitions[$elementTypeName] = $settings;
            }
        }
        return $settingDefinitions;
    }

Usage Example

 /**
  * Test export functionality.
  *
  * @covers ::export
  */
 public function testExport()
 {
     $data = $this->getElementsData();
     $mockElementsService = $this->getMockElementsService($data);
     $this->setComponent(Craft::app(), 'elements', $mockElementsService);
     $data = $this->getElementIndexSettingsData();
     $mockElementIndexesService = $this->getMockElementIndexesService($data);
     $this->setComponent(Craft::app(), 'elementIndexes', $mockElementIndexesService);
     $export = $this->schematicElementIndexSettingsService->export();
     $this->assertEquals($data, $export);
 }