Transform field options.

@param FieldTypeInterface $field

@return array
19679
protected function getOptions(FieldTypeInterface $field)
    {
        $options = parent::getOptions($field);

        $options['items'] = array_map(function ($id) {
            return [
                'attributes' => wp_prepare_attachment_for_js($id),
                'id' => $id
            ];
        }, (array) $field->getValue());

        return $options;
    }
797593
public function map(Field $field)
    {
        $values = array();

        foreach ((array)$field->value as $value) {
            $values[] = $this->convert($value);
        }

        return $values;
    }
1256575
public function getOptions(array $fields = [])
    {
        if (!empty($fields)) {
            return \array_filter(\array_intersect_key($this->getParams(), \array_flip($fields)));
        }

        return \array_filter($this->getParams());
    }
613404
public function transformFormField(FormField $field)
    {
        $newfield = $field->performReadOnlyTransformation();

        $fieldname = $field->getName();
        if ($this->original->isLocalizedField($fieldname)) {
            $field->setName($this->original->getLocalizedFieldName($fieldname));
            $value = $this->original->getLocalizedValue($fieldname);
            if ($value instanceof DBField) {
                $field->setValue($value->getValue());
            } else {
                $field->setValue($value);
            }
        }

        return $this->baseTransform($newfield, $field, $fieldname);
    }
1050958
protected function getFieldValue(string $field, string $value): array
    {
        return [
            'type' => $this->searchFields[$field]['type'],
            'operator' => key($this->searchFields[$field]['operators']),
            'value' => $value
        ];
    }
841727
protected function formatItemField(ItemFieldInterface $field, ItemInterface $item)
    {
        $elements = [];

        $method = $field->getMethod();
        $values = $item->{$method}();

        if (null === $values) {
            return $elements;
        }

        if (!is_array($values)) {
            $values = [$values];
        }

        foreach ($values as $value) {
            $elements[] = $this->formatWithOptions($field, $item, $value);
        }

        return $elements;
    }
1350883
public function getFieldType($field)
    {
        return isset($this->getFieldsConfig()[$field]) ? $this->getFieldsConfig()[$field]['type'] : null;
    }
372598
public function transform(FieldTypeInterface $form)
    {
        return [
            'attributes' => $form->getAttributes(),
            'flush' => $form->getOption('flush', true),
            'locale' => $form->getLocale(),
            'nonce' => $form->getOption('nonce', '_themosisnonce'),
            'referer' => $form->getOption('referer', true),
            'tags' => $form->getOption('tags', true),
            'theme' => $form->getOption('theme', 'themosis'),
            'type' => $form->getType(),
            'validation' => [
                'errors' => $form->getOption('errors', true),
                'isValid' => $form->isValid()
            ]
        ];
    }
702174
protected function getFieldClientOptions($field)
    {
        $attribute = Html::getAttributeName($field->attribute);
        if (!in_array($attribute, $field->model->activeAttributes(), true)) {
            return [];
        }

        $clientValidation = $field->isClientValidationEnabled();
        $ajaxValidation = $field->isAjaxValidationEnabled();

        if ($clientValidation) {
            $validators = [];
            foreach ($field->model->getActiveValidators($attribute) as $validator) {
                /* @var $validator \yii\validators\Validator */
                if (!$validator->enableClientValidation) {
                    continue;
                }

                $js = $validator->clientValidateAttribute($field->model, $attribute, $field->form->getView());
                if ($js === null || $js === '') {
                    $js = $this->buildClientValidator($validator, $field->model, $attribute, $field->form->getView());
                }

                if ($js !== '') {
                    if ($validator->whenClient !== null) {
                        $js = "if (({$validator->whenClient})(attribute, value)) { $js }";
                    }
                    $validators[] = $js;
                }
            }
        }

        if (!$ajaxValidation && (!$clientValidation || empty($validators))) {
            return [];
        }

        $options = [];

        $inputID = $field->getInputId();
        $options['id'] = Html::getInputId($field->model, $field->attribute);
        $options['name'] = $field->attribute;

        $options['container'] = $field->selectors['container'] ?? ".field-$inputID";
        $options['input'] = $field->selectors['input'] ?? "#$inputID";
        if (isset($field->selectors['error'])) {
            $options['error'] = $field->selectors['error'];
        } elseif (isset($field->errorOptions['class'])) {
            $options['error'] = '.'.implode('.', preg_split('/\s+/', $field->errorOptions['class'], -1, PREG_SPLIT_NO_EMPTY));
        } else {
            $options['error'] = $field->errorOptions['tag'] ?? 'span';
        }

        $options['encodeError'] = !isset($field->errorOptions['encode']) || $field->errorOptions['encode'];
        if ($ajaxValidation) {
            $options['enableAjaxValidation'] = true;
        }
        foreach (['validateOnChange', 'validateOnBlur', 'validateOnType', 'validationDelay'] as $name) {
            $options[$name] = $field->$name ?? $field->form->$name;
        }

        if (!empty($validators)) {
            $options['validate'] = new JsExpression('function (attribute, value, messages, deferred, $form) {'.implode('', $validators).'}');
        }

        if ($field->addAriaAttributes === false) {
            $options['updateAriaInvalid'] = false;
        }

        return $options;
    }
1144127
public static function fieldsOfType(ElementInterface $element, string $fieldType): array
    {
        $foundFields = [];

        $layout = $element->getFieldLayout();
        if ($layout === null) {
            return [];
        }
        $fields = $layout->getFields();
        /** @var  $field BaseField */
        foreach ($fields as $field) {
            if ($field instanceof $fieldType) {
                $foundFields[] = $field->handle;
            }
        }

        return $foundFields;
    }
939307
protected function sanitize(FieldTypeInterface $field)
    {
        return function ($value, $key, $type) use ($field) {
            $validator = $this->validator->make(
                [$key => $value],
                $this->getTermRules(),
                $this->getTermMessages(),
                $this->getTermPlaceholders()
            );

            $validation = $validator->valid();

            return $validation[$key] ?? null;
        };
    }
1012535
public function transform($fieldOptions)
    {
        $result = array();
        if (is_array($fieldOptions)) {
            foreach ($fieldOptions as $fieldOption) {
                if($fieldOption instanceof FieldOptionInterface) {
                    $result[$fieldOption->getKey()] = $fieldOption->getValue();
                }
            }
        }

        return $result;
    }
512597
public function error($field)
    {
        $parts = explode('.', $field);
        $entity = $this->entity($parts);

        if ($entity instanceof EntityInterface) {
            return $entity->getError(array_pop($parts));
        }

        return [];
    }
274116
public function getField($field)
    {
        if (!$this->isFieldSupported($field)) {
            return null;
        }

        if (!$this->hasLoadedField($field)) {
            $loaderData = $this->getLoaderData($field);
            if ($normalizer = $this->normalizersMap->getNormalizerForField($field)) {
                switch ($normalizer[ 'type' ]) {
                    case NormalizersMap::TYPE_METHOD:
                        $this->fields[ $field ] =
                            $this->{sprintf('%sNormalizer', $normalizer[ 'method' ])}($loaderData);
                        break;

                    case NormalizersMap::TYPE_ARRAY_PATH:
                        $this->fields[ $field ] =
                            ArrayUtils::getNested($loaderData, $normalizer[ 'path' ], $normalizer[ 'defaultValue' ]);
                        break;

                    case NormalizersMap::TYPE_PREFILLED_VALUE:
                        $this->fields[ $field ] = $normalizer[ 'value' ];
                        break;

                    default:
                        throw new GenericException("Unknown normalizer type \"{$normalizer['type']}\"");
                }

                switch ($field) {
                    case self::FIELD_WEBSITES:
                    case self::FIELD_EXTRA:
                        if ($this->fields[ $field ]) {
                            $this->fields[ $field ] = (array) $this->fields[ $field ];
                        } else {
                            $this->fields[ $field ] = [];
                        }
                        break;
                }
            } // Don't need to be normalized
            else {
                $this->fields[ $field ] = $loaderData;
            }
        }

        return parent::getField($field);
    }
404197
public function addField(FieldInterface $field)
    {
        $this->fields[] = $field;
        $field->setContentType($this);

        return $this;
    }
628636
public function getFieldType($field)
    {
        $definition = $this->getFieldDefinition($field);
        if ($definition && isset($definition['type'])) {
            return $definition['type'];
        }
    }
63217
public function getMappingFieldOptions(AttributeInterface $attribute)
    {
        $options = [
            'is_searchable'       => $attribute->getIsSearchable(),
            'is_filterable'       => $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch(),
            'search_weight'       => $attribute->getSearchWeight(),
            'is_used_for_sort_by' => $attribute->getUsedForSortBy(),
        ];

        if ($attribute->getIsUsedInSpellcheck()) {
            $options['is_used_in_spellcheck'] = true;
        }

        if ($attribute->getIsDisplayedInAutocomplete()) {
            $options['is_filterable'] = true;
        }

        if ($attribute->getUsedForSortBy()) {
            $options['sort_order_asc_missing']  = $attribute->getSortOrderAscMissing();
            $options['sort_order_desc_missing'] = $attribute->getSortOrderDescMissing();
        }

        return $options;
    }