Smile\ElasticsuiteCore\Index\Mapping::addField PHP Method

addField() private method

The field is append and the new properties list is returned.
private addField ( array $properties, Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface $field ) : array
$properties array Initial properties map.
$field Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface Field to be added.
return array
    private function addField(array $properties, FieldInterface $field)
    {
        $fieldName = $field->getName();
        $fieldRoot =& $properties;
        // Read property config from the field.
        $property = $field->getMappingPropertyConfig();
        if ($field->isNested()) {
            /*
             * Nested field management :
             *
             * For nested field we need to
             *   - change the insertion root to the parent field.
             *   - create the parent field with type nested if not yet exists.
             *   - using the suffix name of the field instead of the name including nested path.
             *
             * Ex: "price.is_discount" field has to be inserted with name "is_discount" into the "price" field.
             *
             */
            $nestedPath = $field->getNestedPath();
            if (!isset($properties[$nestedPath])) {
                $properties[$nestedPath] = ['type' => FieldInterface::FIELD_TYPE_NESTED, 'properties' => []];
            }
            $fieldRoot =& $properties[$nestedPath]['properties'];
            $fieldName = $field->getNestedFieldName();
        } elseif (strstr($fieldName, '.')) {
            $fieldPathArray = explode('.', $fieldName);
            if (!isset($properties[current($fieldPathArray)])) {
                $properties[current($fieldPathArray)] = ['type' => FieldInterface::FIELD_TYPE_OBJECT, 'properties' => []];
            }
            $fieldRoot =& $properties[current($fieldPathArray)]['properties'];
            $fieldName = end($fieldPathArray);
        }
        /*
         * Retrieving location where the property has to be copied to.
         * Ex : searchable fields are copied to default "search" field.
         */
        $copyToProperties = $this->getFieldCopyToProperties($field);
        if (!empty($copyToProperties)) {
            // For normal fields, copy_to is append at the property root.
            $copyToRoot =& $property;
            if ($property['type'] == FieldInterface::FIELD_TYPE_MULTI) {
                /*
                 * For field with type "multi_field", the copy_to has to be added in the
                 * default subfield.
                 * This is changing the root.
                 */
                $copyToRoot =& $property['fields'][$fieldName];
            }
            $copyToRoot['copy_to'] = $copyToProperties;
        }
        $fieldRoot[$fieldName] = $property;
        return $properties;
    }