Searches mappings on element for versioned fields.

@param \SimpleXMLElement $element
@param array             $config
@param object            $meta
966360
private function inspectElementForVersioned(\SimpleXMLElement $element, array &$config, $meta)
    {
        foreach ($element as $mapping) {
            $mappingDoctrine = $mapping;
            /**
             * @var \SimpleXmlElement
             */
            $mapping = $mapping->children(self::GEDMO_NAMESPACE_URI);

            $isAssoc = $this->_isAttributeSet($mappingDoctrine, 'field');
            $field = $this->_getAttribute($mappingDoctrine, $isAssoc ? 'field' : 'name');

            if (isset($mapping->versioned)) {
                if ($isAssoc && !$meta->associationMappings[$field]['isOwningSide']) {
                    throw new InvalidMappingException("Cannot version [{$field}] as it is not the owning side in object - {$meta->name}");
                }
                $config['versioned'][] = $field;
            }
        }
    }
626688
public static function parseChildren($config, Form_Elements_FieldsetModel $container)
	{
		$contextProfile = AgaviConfig::get('core.default_context');
		if(is_null($contextProfile))
		{
			$contextProfile = md5(microtime());
			AgaviConfig::set('core.default_context', $contextProfile);
		}
		$context = AgaviContext::getInstance();
		if(isset($config->items) and is_array($config->items))
		{
			foreach($config->items as $item)
			{
				if(isset($item->xtype))
				{
					switch($item->xtype)
					{
						case 'textfield':
							if(isset($item->inputType) and $item->inputType=='password')
								$model = array('Elements.PasswordField', 'Form');
							else
								$model = array('Elements.TextField', 'Form');
							break;
						case 'numberfield':
							$model = array('Elements.NumberField', 'Form');
							break;
						case 'combo':
							$model = array('Elements.ResourceField', 'Form');
							break;
						case 'datefield':
							$model = array('Elements.DateField', 'Form');
							break;
						case 'radiogroup':
							$model = array('Elements.RadioGroup', 'Form');
							break;
						case 'checkbox':
							$model = array('Elements.Checkbox', 'Form');
							break;
						case 'fieldset':
							$model = Form_Elements_FieldsetModel::fromJson($item, $container);
							break;
						case 'textarea':
							$model = array('Elements.TextArea', 'Form');
							break;
						default:
							$model = null;
					}
					if(is_array($model))
					{
						$el = $context->getModel($model[0], $model[1], array($item, $container));
						$container->addChild($el);
					}
					elseif(!is_null($model))
					{
						$container->addChild($model);
					}
				}
			}
		}
	}
440787
public function set_element_default($element, $defaultvalue) {
        if ($element instanceof HTML_QuickForm_element) {
            $element = $element->getName();
        }
        $this->_form->setDefault($element, $defaultvalue);
    }
130488
protected function loadTranslatableMetadata($className, $config)
    {
        if (!$config) {
            return;
        }

        $xml = new SimpleXMLElement($config);

        $xml->registerXPathNamespace('prezent', 'prezent');

        $nodeList = $xml->xpath('//prezent:translatable');
        if (0 == count($nodeList)) {
            return;
        }

        if (1 < count($nodeList)) {
            throw new \Exception("Configuration defined twice");
        }

        $node = $nodeList[0];

        $classMetadata = new TranslatableMetadata($className);

        $translatableField = (string)$node['field'];

        $propertyMetadata = new PropertyMetadata(
            $className,
            // defaults to translatable
            !empty($translatableField) ? $translatableField : 'translations'
        );

        // default targetEntity
        $targetEntity = $className . 'Translation';

        $translatableTargetEntity    = (string)$node['target-entity'];
        $classMetadata->targetEntity = !empty($translatableTargetEntity) ? $translatableTargetEntity : $targetEntity;
        $classMetadata->translations = $propertyMetadata;
        $classMetadata->addPropertyMetadata($propertyMetadata);

        $currentLocale = (string)$node['current-locale'];
        if (!empty($currentLocale)) {
            $propertyMetadata = new PropertyMetadata($className, $currentLocale);

            $classMetadata->currentLocale = $propertyMetadata;
            $classMetadata->addPropertyMetadata($propertyMetadata);
        }

        $fallbackLocale = (string)$node['fallback-locale'];
        if (!empty($fallbackLocale)) {
            $propertyMetadata = new PropertyMetadata($className, $fallbackLocale);

            $classMetadata->fallbackLocale = $propertyMetadata;
            $classMetadata->addPropertyMetadata($propertyMetadata);
        }

        return $classMetadata;
    }
458142
private function inspectEmbeddedForVersioned($field, array &$config, \Doctrine\ORM\Mapping\ClassMetadata $meta)
    {
        $сlass = new \ReflectionClass($meta->embeddedClasses[$field]['class']);

        // property annotations
        foreach ($сlass->getProperties() as $property) {
            // versioned property
            if ($this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
                $config['versioned'][] = $field . '.' . $property->getName();
            }
        }
    }
1170592
protected function _loadExistingClass($class, &$meta) {
        try {
            $reflector = new xPDOReflectionClass($class);

            $classHeader = rtrim($reflector->getSource(null, 0, $reflector->getStartLine() - 1, false), "\n");
            $classFooter = trim($reflector->getSource(null, $reflector->getEndLine(), null, false), " \n\r\t");
            if (!empty($classFooter)) $classFooter = rtrim($classFooter, "\n");

            $interfaces = $reflector->getInterfaceNames();
            if (!empty($interfaces)) {
                $interfaces = " implements " . implode(', ', $interfaces);
            } else {
                $interfaces = '';
            }

            $constants = $reflector->getConstants();

            $properties = array_filter($reflector->getProperties(), function($property) use ($class) {
                /* @var \ReflectionProperty $property */
                return $property->getDeclaringClass() === ltrim($class, '\\');
            });
            $methods = array_filter($reflector->getMethods(), function($method) use ($class) {
                /* @var \ReflectionMethod $method */
                return $method->getDeclaringClass() === ltrim($class, '\\');
            });

            $traitArray = array();
            if (version_compare(PHP_VERSION, '5.4', '>=')) {
                $traits = $reflector->getTraits();

                /* @var \ReflectionClass $trait */
                foreach ($traits as $trait) {
                    $traitArray[] = "    use \\{$trait->getName()};";
                }
            }

            $constantsArray = array();
            foreach ($constants as $constantKey => $constant) {
                $constantsArray[] = "    const {$constantKey} = " . static::varExport($constant) . ';';
            }

            $propertyArray = array();
            /* @var \ReflectionProperty $property */
            foreach ($properties as $property) {
                $propertyArray[] = $reflector->getSource($property);
            }

            $methodArray = array();
            /* @var \ReflectionMethod $method */
            foreach ($methods as $method) {
                $methodArray[] = $reflector->getSource($method);
            }

            $meta['class-header'] = "{$classHeader}\n";
            $meta['class-declaration'] = "class {$reflector->getShortName()} extends \\{$reflector->getParentClass()->getName()}{$interfaces}\n{";
            $meta['class-constants'] = implode("\n", $constantsArray);
            if (version_compare(PHP_VERSION, '5.4', '>=')) {
                $meta['class-traits'] = implode("\n", $traitArray);
            }
            $meta['class-properties'] = implode("\n", $propertyArray);
            $meta['class-methods'] = implode("\n", $methodArray);
            $meta['class-close-declaration'] = "}\n";
            $meta['class-footer'] = $classFooter;
        } catch (\Exception $e) {
            $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
        }
    }
121625
public function shouldParseElementOnMove(Element $element): bool
    {
        $fieldLayout = $element->getFieldLayout();

        if ($fieldLayout) {
            foreach ($fieldLayout->getFields() as $field) {
                if ($field && \get_class($field) === 'aelvan\preparsefield\fields\PreparseFieldType') {
                    /** @var PreparseFieldType $field */
                    $parseOnMove = $field->parseOnMove;

                    if ($parseOnMove) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
856177
public function configElem($config, $el = NULL)
	{
		if (is_scalar($config)) {
			$config = $this->fetchConfig($config);
		}

		// first define which element we want to work with
		if (isset($config[ Cnf::elementName ])) {
			$name = $config[ Cnf::elementName ];
			if (!$el) {
				// element does not exist, so create it
				$el = Html::el($name);
			} else {
				// element exists, but we want to change its name
				$el->setName($name);
			}
		}

		if ($el instanceof Html && $el != NULL) {
			// if el is defined, we can configure it accordingly

			// go through all config and configure element accordingly
			foreach ($config as $key => $value) {
				if (in_array($key, [Cnf::classSet, Cnf::classAdd, Cnf::classAdd, Cnf::classRemove])) {
					// we'll be working with classes, we must standardize everything to arrays, not strings for the sake of sanity
					if (!is_array($value)) {
						// configuration may contain classes as strings, but we always work with arrays
						$value = [$value];
					}

					$origClass = $el->getAttribute('class');
					$newClass = $origClass;
					if ($origClass === NULL) {
						// class is not set
						$newClass = [];
					} elseif (!is_array($origClass)) {
						// class is set, but not a array
						$newClass = explode(' ', $el->getAttribute('class'));
					}
					$el->setAttribute('class', $newClass);
					$origClass = $newClass;
				}

				if ($key == Cnf::classSet) {
					$el->setAttribute('class', $value);
				} elseif ($key == Cnf::classAdd) {
					$el->setAttribute(
						'class',
						array_merge($origClass, $value)
					);
				} elseif ($key == Cnf::classRemove) {
					$el->setAttribute(
						'class',
						array_diff($origClass, $value)
					);
				} elseif ($key == Cnf::attributes) {
					foreach ($value as $attr => $attrVal) {
						$el->setAttribute($attr, $attrVal);
					}
				}
			}
		}

		// el may be null, but maybe it has a container defined
		if (isset($config[ Cnf::container ])) {
			$container = $this->configElem($config[ Cnf::container ], NULL);
			if ($container !== NULL && $el !== NULL) {
				$elClone = clone $el;
				$container->setHtml($elClone);
			}
			$el = $container;
		}

		return $el;
	}
1172600
protected function unmarshall(DOMElement $element)
    {
        try {
            $mapKey = $this->getDOMElementAttributeAs($element, 'mapKey');
            $mapKey = Utils::stringToDatatype($mapKey, $this->getBaseType());

            if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {

                $object = new MapEntry($mapKey, $mappedValue);

                if (Version::compare($this->getVersion(), '2.0.0', '>') && ($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
                    $object->setCaseSensitive($caseSensitive);
                }

                return $object;
            } else {
                $msg = "The mandatory 'mappedValue' attribute is missing from element '" . $element->nodeName . "'.";
                throw new UnmarshallingException($msg, $element);
            }
        } catch (UnexpectedValueException $e) {
            $msg = "The value '${mapKey}' of the 'mapKey' attribute could not be converted to a '" . BaseType::getNameByConstant($this->getBaseType()) . "' value.";
            throw new UnmarshallingException($msg, $element, $e);
        }
    }
910574
public function mapFields($meta, array $fieldOverrides)
    {
        /* @var $fieldOverride EmbeddedOverride */
        foreach ($fieldOverrides as $fieldOverride) {
            list($embedded, $property) = explode('.', $fieldOverride->name);

            if (!$meta->hasField($fieldOverride->name) || !isset($meta->embeddedClasses[$embedded])) {
                continue;
            }

            $fieldMapping = $meta->getFieldMapping($fieldOverride->name);
            $fieldMapping = array_merge($fieldMapping, $this->columnToArray($fieldOverride->column));

            $meta->setAttributeOverride($fieldOverride->name, $fieldMapping);
        }
    }
1237317
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
    {
        // metadata
        $metadata .= $owner->MarkupComment('Metadata');
        // charset
        if ($config->CharsetEnabled()) {
            $metadata .= '<meta charset="' . $config->Charset() . '" />' . PHP_EOL;
        }
        // canonical
        if ($config->CanonicalEnabled()) {
            $metadata .= $owner->MarkupLink('canonical', $owner->AbsoluteLink());
        }
        // title
        if ($config->TitleEnabled()) {
            $metadata .= '<title>' . $owner->encodeContent($owner->GenerateTitle(), $config->Charset()) . '</title>' . PHP_EOL;
        }
        // description
        if ($description = $owner->GenerateDescription()) {
            $metadata .= $owner->MarkupMeta('description', $description, $config->Charset());
        }
        // extra metadata
        if ($config->ExtraMetaEnabled()) {
            $metadata .= $owner->MarkupComment('Extra Metadata');
            $metadata .= $owner->GenerateExtraMeta();
        }
    }
600858
public function readExtendedMetadata($meta, array &$config)
    {
        $class = $this->getMetaReflectionClass($meta);
        /* @var $embeddedOverrides EmbeddedOverrides */
        if (!($embeddedOverrides = $this->reader->getClassAnnotation($class, EmbeddedOverrides::class))) {
            return;
        }

        $config['embeddedOverrides'] = [];

        /* @var $embeddedOverride EmbeddedOverride */
        foreach ($embeddedOverrides->value as $embeddedOverride) {
            $fieldName = $embeddedOverride->name;

            if (false === strpos($fieldName, '.')) {
                continue;
            }

            list($fieldName, ) = explode('.', $fieldName);

            if (!$class->hasProperty($fieldName)) {
                throw new MappingException(sprintf(
                    "Property %s doesn't exist",
                    $meta->getName() . '::$' . $fieldName
                ));
            }

            if ($meta->isMappedSuperclass && !$class->getProperty($fieldName)->isPrivate() ||
                $meta->isInheritedField($embeddedOverride->name) ||
                !isset($meta->embeddedClasses[$fieldName])
            ) {
                continue;
            }

            $config['embeddedOverrides'][] = $embeddedOverride;
        }
    }
688621
public function set(string $element, string $nameId = null): void
    {
        $nameId != null ? $this->elements[$nameId] = $element : $this->elements[] = $element;
    }
639058
protected function addAttributes($element, $data)
    {
        foreach ($data as $attrKey => $attrVal) {
            $element->setAttribute($attrKey, $attrVal);
        }
    }
1019955
public static function setVal($metaKey, $elementKey, $elementId, $value)
    {
        $data = self::create()
            ->filterByMetaKey($metaKey)
            ->filterByElementKey($elementKey)
            ->filterByElementId($elementId)
            ->findOne()
        ;

        if (null === $data) {
            $data = new MetaData();
            $data->setMetaKey($metaKey);
            $data->setElementKey($elementKey);
            $data->setElementId($elementId);
        }

        $data->setValue($value);

        $data->save();
    }
117363
private function mapElements(array $elements, array $mainElements, array &$map, array &$inverse): void
    {
        foreach ($elements as $index => $element) {
            $elementId = (int) $element['id'];
            if (!array_key_exists($index, $mainElements)) {
                $this->logger->warning(
                    'Content element {id} has no mapping in main. Element skipped.',
                    [
                        'id' => $elementId,
                        'msg_type' => 'article_content_no_main',
                    ]
                );
                continue;
            }
            $mainElement = $mainElements[$index];
            $mainId      = (int) $mainElement['id'];
            if ($element['type'] !== $mainElement['type']) {
                $this->logger->warning(
                    'Content element {id} has different type as element in main. Element skipped.',
                    [
                        'id' => $elementId,
                        'mainId' => $mainId,

                        'msg_type' => 'article_content_type_mismatch'
                    ]
                );
                continue;
            }

            $map[$elementId]  = $mainId;
            $inverse[$mainId] = $elementId;
        }
    }
1278248
private function guessProperty(ClassMetadata $metadata, $element)
    {
        // Is it the element the actual property
        if ($metadata->hasPropertyMetadata($element)) {
            return $element;
        }

        // Is it a camelized property
        $camelized = $this->camelize($element);
        if ($metadata->hasPropertyMetadata($camelized)) {
            return $camelized;
        }

        return null;
    }