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

import() public method

Attempt to import fields.
public import ( array $groupDefinitions, boolean $force = false ) : Result
$groupDefinitions array
$force boolean if set to true items not in the import will be deleted
return Result
    public function import(array $groupDefinitions, $force = false)
    {
        Craft::log(Craft::t('Importing Fields'));
        if (!empty($groupDefinitions)) {
            $contentService = $this->getContentService();
            $contentService->fieldContext = 'global';
            $contentService->contentTable = 'content';
            $this->resetCraftFieldsServiceGroupsCache();
            $this->groups = $this->getFieldsService()->getAllGroups('name');
            $this->fields = $this->getFieldsService()->getAllFields('handle');
            foreach ($groupDefinitions as $name => $fieldDefinitions) {
                try {
                    $this->beginTransaction();
                    $group = $this->createFieldGroupModel($name);
                    $this->importFields($fieldDefinitions, $group);
                    $this->commitTransaction();
                } catch (\Exception $e) {
                    $this->rollbackTransaction();
                    $this->addError($e->getMessage());
                }
                $this->unsetData($name, $fieldDefinitions);
            }
            if ($force) {
                // Remove not imported data
                $this->deleteFieldsAndGroups();
            }
            $this->resetCraftFieldsServiceFieldsCache();
        }
        return $this->getResultModel();
    }