public function getFieldLayout(array $fieldLayoutDef): FieldLayout
    {
        $layoutFields = [];
        $requiredFields = [];

        if (array_key_exists('tabs', $fieldLayoutDef)) {
            foreach ($fieldLayoutDef['tabs'] as $tabName => $tabDef) {
                $layoutTabFields = $this->getPrepareFieldLayout($tabDef);
                $requiredFields = array_merge($requiredFields, $layoutTabFields['required']);
                $layoutFields[$tabName] = $layoutTabFields['fields'];
            }
        } elseif (array_key_exists('fields', $fieldLayoutDef)) {
            $layoutTabFields = $this->getPrepareFieldLayout($fieldLayoutDef);
            $requiredFields = $layoutTabFields['required'];
            $layoutFields = $layoutTabFields['fields'];
        }

        $fieldLayout = Craft::$app->fields->assembleLayout($layoutFields, $requiredFields);

        if (array_key_exists('type', $fieldLayoutDef)) {
            $fieldLayout->type = $fieldLayoutDef['type'];
        } else {
            $fieldLayout->type = Entry::class;
        }

        return $fieldLayout;
    }
public function getFieldLayout(array $fieldLayoutDef): FieldLayout
    {
        $layoutFields = [];
        $requiredFields = [];

        if (array_key_exists('tabs', $fieldLayoutDef)) {
            foreach ($fieldLayoutDef['tabs'] as $tabName => $tabDef) {
                $layoutTabFields = $this->getPrepareFieldLayout($tabDef);
                $requiredFields = array_merge($requiredFields, $layoutTabFields['required']);
                $layoutFields[$tabName] = $layoutTabFields['fields'];
            }
        } elseif (array_key_exists('fields', $fieldLayoutDef)) {
            $layoutTabFields = $this->getPrepareFieldLayout($fieldLayoutDef);
            $requiredFields = $layoutTabFields['required'];
            $layoutFields = $layoutTabFields['fields'];
        }

        $fieldLayout = Craft::$app->fields->assembleLayout($layoutFields, $requiredFields);

        if (array_key_exists('type', $fieldLayoutDef)) {
            $fieldLayout->type = $fieldLayoutDef['type'];
        } else {
            $fieldLayout->type = Entry::class;
        }

        return $fieldLayout;
    }
public function getFieldLayout ( array $ fieldLayoutDef ) : FieldLayout { $ layoutFields = [ ] ; $ requiredFields = [ ] ; if ( array_key_exists ( 'tabs' , $ fieldLayoutDef ) ) { foreach ( $ fieldLayoutDef [ 'tabs' ] as $ tabName => $ tabDef ) { $ layoutTabFields = $ this -> getPrepareFieldLayout ( $ tabDef ) ; $ requiredFields = array_merge ( $ requiredFields , $ layoutTabFields [ 'required' ] ) ; $ layoutFields [ $ tabName ] = $ layoutTabFields [ 'fields' ] ; } } elseif ( array_key_exists ( 'fields' , $ fieldLayoutDef ) ) { $ layoutTabFields = $ this -> getPrepareFieldLayout ( $ fieldLayoutDef ) ; $ requiredFields = $ layoutTabFields [ 'required' ] ; $ layoutFields = $ layoutTabFields [ 'fields' ] ; } $ fieldLayout = Craft :: $ app -> fields -> assembleLayout ( $ layoutFields , $ requiredFields ) ; if ( array_key_exists ( 'type' , $ fieldLayoutDef ) ) { $ fieldLayout -> type = $ fieldLayoutDef [ 'type' ] ; } else { $ fieldLayout -> type = Entry :: class ; } return $ fieldLayout ; }
Attempt to import a field layout.

@param array $fieldLayoutDef

@return FieldLayout
Attempt to import a field layout .