NerdsAndCompany\Schematic\Services\Sections::import PHP Метод

import() публичный Метод

Attempt to import sections.
public import ( array $sectionDefinitions, boolean $force = false ) : Result
$sectionDefinitions array
$force boolean If set to true sections not included in the import will be deleted
Результат Result
    public function import(array $sectionDefinitions, $force = false)
    {
        Craft::log(Craft::t('Importing Sections'));
        $sections = Craft::app()->sections->getAllSections('handle');
        foreach ($sectionDefinitions as $sectionHandle => $sectionDefinition) {
            $section = array_key_exists($sectionHandle, $sections) ? $sections[$sectionHandle] : new SectionModel();
            unset($sections[$sectionHandle]);
            if ($sectionDefinition === $this->getSectionDefinition($section, null)) {
                Craft::log(Craft::t('Skipping `{name}`, no changes detected', ['name' => $section->name]));
                continue;
            }
            if (!array_key_exists('locales', $sectionDefinition)) {
                $this->addError('`sections[handle].locales` must be defined');
                continue;
            }
            if (!array_key_exists('entryTypes', $sectionDefinition)) {
                $this->addError('errors', '`sections[handle].entryTypes` must exist be defined');
                continue;
            }
            Craft::log(Craft::t('Importing section `{name}`', ['name' => $sectionDefinition['name']]));
            $this->populateSection($section, $sectionDefinition, $sectionHandle);
            $this->resetCraftFieldsSectionModelCache($section);
            // Create initial section record
            if (!$this->preSaveSection($section)) {
                $this->addErrors($section->getAllErrors());
                continue;
            }
            $this->importEntryTypes($section, $sectionDefinition['entryTypes'], $force);
            // Save section via craft after entrytypes have been created
            if (!Craft::app()->sections->saveSection($section)) {
                $this->addErrors($section->getAllErrors());
            }
        }
        if ($force) {
            foreach ($sections as $section) {
                Craft::app()->sections->deleteSectionById($section->id);
            }
        }
        return $this->getResultModel();
    }