Compile changes for embed field types.

@param string $key
@param string $value
@param array  $fields

@return array
352970
private function fieldOembed($key, $value, array $fields)
    {
        $before = Json::parse($value[0]);
        $after = Json::parse($value[1]);

        return [
            'type'   => $fields[$key]['type'],
            'before' => [
                'render' => [
                    'url'           => $before['url'],
                    'type'          => $before['type'],
                    'author_name'   => $before['author_name'],
                    'author_url'    => $before['author_url'],
                    'provider_name' => $before['provider_name'],
                    'provider_url'  => $before['provider_url'],
                    'height'        => $before['height'],
                    'width'         => $before['width'],
                    'html'          => $before['html'],
                ],
            ],
            'after'  => [
                'render' => [
                    'url'           => $after['url'],
                    'type'          => $after['type'],
                    'author_name'   => $after['author_name'],
                    'author_url'    => $after['author_url'],
                    'provider_name' => $after['provider_name'],
                    'provider_url'  => $after['provider_url'],
                    'height'        => $after['height'],
                    'width'         => $after['width'],
                    'html'          => $after['html'],
                ],
            ],
        ];
    }
144369
private static function updateFieldStrVal(&$field, $values, $key)
    {
        if (isset($values[$key]) && is_string($values[$key])) {
            $field->{$key} = $values[$key];
        }
    }
635293
protected function fillEmbed($key, $value)
    {
        $attrs = $this->getAttrs();
        $cache = &$this->_cache;
        $embed = $attrs[$key];
        $model = $embed['model'];
        $type = $embed['type'];

        if ($type == self::DATA_TYPE_EMBED) {
            $model = $embed['model'];
            if ($value instanceof $model) {
                $value->embed = true;
                $return  = $value->toArray(array('_type','_id'));
            } elseif ($value === null) {
                $return = null;
            } elseif (isset($value, $value['$ref'], $value['$id'])) {
                $value = $model::id($value['$id']);
                $ref = $value->makeRef();
                $return = $ref;
            } else {
                throw new \Exception("{$key} is not instance of '$model'");
            }

        } elseif ($type == self::DATA_TYPE_EMBEDS) {
            $arr = array();
            if (is_array($value)) {
                foreach ($value as $item) {
                    if(! ( $item instanceof Model ) ) continue;
                    $item->embed = true;
                    $arr[] = $item;
                }
                $value = Collection::make($arr);
            }

            if ($value instanceof Collection) {
                $return = $value->toEmbedsArray();
            } elseif ($value === null) {
                $return = null;
            } else {
                throw new \Exception("{$key} is not instance of '$model'");
            }
        }

        $cache[$key] = $value;

        return $return;
    }
904934
private function replace($key, $value)
  {
    if (is_array($value)) return $this->cleanData($value);

    return $this->transform($key, $value);
  }
1252980
public function prepend($value, $key = null): Arrayy
    {
        $this->checkTypeWrapper($value);

        return parent::prepend($value, $key);
    }
544788
private static function _autoUpdateFromFields(&$fields)
    {
        $addKeywords = [null, null];
        $removeKeywords = [null, null];

        if (isset($fields->add) && isset($fields->add->first_word)) {
            $addKeywords[0] = $fields->add->first_word;
        }

        if (isset($fields->add) && isset($fields->add->second_word)) {
            $addKeywords[1] = $fields->add->second_word;
        }

        if (isset($fields->remove) && isset($fields->remove->first_word)) {
            $removeKeywords[0] = $fields->remove->first_word;
        }

        if (isset($fields->remove) && isset($fields->remove->second_word)) {
            $removeKeywords[1] = $fields->remove->second_word;
        }

        return new Api\GroupAutoUpdate(
            $fields->to, $addKeywords, $removeKeywords
        );
    }
102138
function create_new_field_keys( &$field )
	{
		// update key
		$field['key'] = 'field_' . uniqid();
		
		
		if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
		{
			foreach( $field['sub_fields'] as $f )
			{
				$this->create_new_field_keys( $f );
			}
		}
		elseif( isset($field['layouts']) && is_array($field['layouts']) )
		{
			foreach( $field['layouts'] as $layout )
			{
				if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
				{
					foreach( $layout['sub_fields'] as $f )
					{
						$this->create_new_field_keys( $f );
					}
				}
				
			}
		}
	}
272672
public function hSet($key, $field, $value) {
        return $this->getHandler($this->judge(__FUNCTION__))->hSet($key, $field, $value);
    }
1221746
public function updateCMSFields(FieldList $fields)
    {
        $owner = $this->owner;
        $tab = $owner->config()->get('embed_tab');
        $tab = isset($tab) ? $tab : 'Main';

        // Ensure these fields don't get added by fields scaffold
        $fields->removeByName([
            'EmbedTitle',
            'EmbedType',
            'EmbedSourceURL',
            'EmbedSourceImageURL',
            'EmbedHTML',
            'EmbedWidth',
            'EmbedHeight',
            'EmbedAspectRatio',
            'EmbedDescription',
            'EmbedImage'
        ]);

        $fields->addFieldsToTab(
            'Root.' . $tab,
            array(
                TextField::create(
                    'EmbedTitle',
                    _t(__CLASS__ . '.TITLELABEL', 'Title')
                )
                ->setDescription(
                    _t(__CLASS__ . '.TITLEDESCRIPTION', 'Optional. Will be auto-generated if left blank')
                ),
                TextField::create(
                    'EmbedSourceURL',
                    _t(__CLASS__ . '.SOURCEURLLABEL', 'Source URL')
                )
                ->setDescription(
                    _t(__CLASS__ . '.SOURCEURLDESCRIPTION', 'Specify a external URL')
                ),
                UploadField::create(
                    'EmbedImage',
                    _t(__CLASS__ . '.IMAGELABEL', 'Image')
                )
                ->setFolderName($owner->EmbedFolder)
                ->setAllowedExtensions(['jpg','png','gif']),
                TextareaField::create(
                    'EmbedDescription',
                    _t(__CLASS__ . '.DESCRIPTIONLABEL', 'Description')
                )
            )
        );

        if (isset($owner->AllowedEmbedTypes) && Count($owner->AllowedEmbedTypes) > 1) {
            $fields->addFieldToTab(
                'Root.' . $tab,
                ReadonlyField::create(
                    'EmbedType',
                    _t(__CLASS__ . '.TYPELABEL', 'Type')
                ),
                'EmbedImage'
            );
        }

        return $fields;
    }
56567
public function fillKeyField(array &$fields)
    {
        $model   = $this->config->getDataModel();
        $keyName = $model->getKeyName();

        //add the primary key field, which will be uneditable, but part of the data model
        if ($this->config->getType() === 'model' && !isset($fields[$keyName])) {
            $keyField         = $this->make($keyName, array('visible' => false));
            $fields[$keyName] = $keyField->getOptions();
        }
    }
710311
private function getFieldInfo($key, $value): array
    {
        $name = null;
        $options = [];
        if (is_numeric($key) && is_string($value)) {
            $name = $value;
        } else if (is_numeric($key) && is_array($value)) {
            $name = array_shift($value);
            $options = $value;
        } else if (is_string($key)) {
            $name = $key;
            $options = $value;
        }
        return ['name' => $name, 'options' => $options];
    }
1173093
private function fieldPrefixer(array &$fields)
    {
        foreach ($fields as $index => $property) {
            if (0 === \strpos($property, $this->source . '.')
                || !$this->fieldExists($property)
            ) {
                continue;
            }

            $fields[$index] = $this->source . '.' . $property;
        }
    }
1050958
protected function getFieldValue(string $field, string $value): array
    {
        return [
            'type' => $this->searchFields[$field]['type'],
            'operator' => key($this->searchFields[$field]['operators']),
            'value' => $value
        ];
    }
48819
protected function mutateAttributeForArray($key, $value)
    {
        if ($this->hasMapping($key)) {
            $value = $this->mapAttribute($key);

            return $value instanceof Arrayable ? $value->toArray() : $value;
        }

        return parent::mutateAttributeForArray($key, $value);
    }
1335748
public function with($key, $value = '')
    {
        if (is_array($key)) {
            $this->appends = $key;
        } elseif (is_callable($value)) {
            $this->appends[$key] = value($value);
        } else {
            $this->appends[$key] = value($value);
        }

        return $this;
    }
927892
public function hDel($key, $field, ...$fields) {
        return $this->send(array_merge(['hdel', $key], (array) $field, $fields));
    }
1272866
public function hashSet($key, $field, $value) {
        $option = $this->getHashOption($key);
        $option[$field] = $value;
        return $this->setOption($key, $option);
    }