Look for matrix/supertables/neo that are not localized and update the keys to
ensure the site/locale values on child elements remain intact
@param BaseElementModel $element
@param array $data function foo($method)
774482
protected function localizeData(Element $element, Array &$data)
    {
        $fieldLayout = $element->getFieldLayout();
        foreach ($fieldLayout->getTabs() as $tab) {
            foreach ($tab->getFields() as $tabField) {
                $field = Craft::$app->fields->getFieldById($tabField->id);
                $fieldValue = $element[$field->handle];
                if ( in_array ($field->className() , ['craft\fields\Matrix', 'verbb\supertable\fields\SuperTableField', 'benf\neo\Field']) ) {
                    if ($field->localizeBlocks == false) {
                        $items = $fieldValue->getIterator();
                        $i = 1;
                        foreach ($items as $item) {
                            if (key_exists('new'. $i, $data['fields'][$field->handle])) {
                               $data['fields'][$field->handle][$item->id] = $data['fields'][$field->handle]['new' . $i];
                               unset($data['fields'][$field->handle]['new' . $i]);
                            }
                            $i++;
                        }
                    }
                }
            }
        }
    }
714494
public function replaceWith(Element $element) 
	{
		// if the element has a parent
		if ( ! empty($this->parent)) {
			$this->parent->replaceChild($this, $element);
		} else {
			throw new \BadMethodCallException(
				__METHOD__."() expects this element to have a parent element"
			);
		}
		
		return $this;
	}
839306
protected function renderElement(HTMLElement $element, $data = [])
    {
        // Check for actions
        $actions = $data['actions'];

        // Check for "delete" action
        if (isset($actions['delete']) && $actions['delete']) {
            $this->getHTMLHandler()->remove($element);

            return $this;
        }

        // Add/Append all attributes
        foreach ($data['attributes'] as $name => $value) {
            // Evaluate given value using scss syntax (replace & with existing value, for class attributes only)
            $existingValue = $this->getHTMLHandler()->attr($element, $name);
            $value = is_string($value) && $name == 'class' ? str_replace('&', $existingValue, $value) : $value;

            // Set new value
            $this->getHTMLHandler()->attr($element, $name, $value);
        }

        // Add/Append all data attributes
        foreach ($data['data'] as $name => $value) {
            $this->getHTMLHandler()->data($element, $name, $value);
        }

        // Apply style attributes
        foreach ($data['style'] as $name => $value) {
            $this->getHTMLHandler()->style($element, $name, $value);
        }

        // Check for node value
        $nodeValue = $data['nodeValue'];
        if (!is_null($nodeValue)) {
            $this->getHTMLHandler()->nodeValue($element, $nodeValue);
        }

        // Check for inner html
        $innerHTML = $data['innerHTML'];
        if (!is_null($innerHTML)) {
            $this->getHTMLHandler()->innerHTML($element, $innerHTML);
        }

        // Append children
        $appendElements = $actions['append'] ?: [];
        $appendElements = is_array($appendElements) ? $appendElements : [$appendElements];
        foreach ($appendElements as $appendElement) {
            $this->getHTMLHandler()->append($element, $appendElement);
        }

        // Prepend children
        $prependElements = $actions['prepend'] ?: [];
        $prependElements = is_array($prependElements) ? $prependElements : [$prependElements];
        foreach ($prependElements as $prependElement) {
            $this->getHTMLHandler()->prepend($element, $prependElement);
        }

        // Render tag-specific parameters
        $this->renderSelect($element, $data['select']);
        $this->renderForm($element, $data['form']);

        return $this;
    }
200210
private function setProperty($element, $key, $value)
    {
        if (!in_array($element, $this->multiplePropertiesForElementAllowed)
            && isset($this->definedElements[$element])
        ) {
            throw VCardException::elementAlreadyExists($element);
        }

        // we define that we set this element
        $this->definedElements[$element] = true;

        // adding property
        $this->properties[] = [
            'key' => $key,
            'value' => $value
        ];
    }
209496
function (element) {
            // Begin with checking the validate
            var elementAsArray = [ element ],
                validationType = element.getAttribute("data-validate") || null;
                invalidElement = [];
            if (validationType !== null) {
                validationType = this.splitStringByComma(validationType);
                for (var i = 0; i < validationType.length; i++) {
                    invalidElement = this.getElementsByPattern(elementAsArray, this.patterns[validationType[i]], validationType[i]);
                    if (invalidElement.length > 0) {
                        this.currentValidationType = validationType[i];
                        return false;
                    }
                }
            }
            // As data-validate="length" has already been checked,
            // only check the elements with data-length set.
            if (element.getAttribute("data-length") === null ||
                validationType !== null && validationType.indexOf("length") !== -1)
                return true;
            validationType = "length";
            invalidElement = this.getElementsByPattern(elementAsArray, this.patterns[validationType], validationType);
            if (invalidElement.length > 0)
                return false;

            return true;
        }
1210344
function removeElement($element)
    {
        if(get_class($element) !== $this->manager->getModel()){
            throw new InvalidArgumentException("This element is not compatible with this collection, it only support  ".$this->manager->getModel());
        }

        $key = array_search($element, $this->elements, true);

        if ($key !== false) {
            unset($this->elements[$key]);

            return true;
        }

        return false;
    }
1156222
protected function removeFromTreeByElement(Model $element)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($element);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $this->removeFromTreeByLftRgt($connection, $tableName, $element->__lft, $element->__rgt);
    }
157161
protected function expandTreeInElementLast($element, $width)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($element);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();
        $this->expandTreeBeforeRgt($connection, $tableName, $element->__rgt, $width);
    }
1125827
function processBySchemaTree( $element )
    {
        $parent = $element->parentNode;

        if ( $parent instanceof DOMElement )
        {
            $schemaCheckResult = $this->XMLSchema->check( $parent, $element );
            if ( !$schemaCheckResult )
            {
                if ( $schemaCheckResult === false )
                {
                    // Remove indenting spaces
                    if ( $element->nodeType == XML_TEXT_NODE && !trim( $element->textContent ) )
                    {
                        $element = $parent->removeChild( $element );
                        return false;
                    }

                    $elementName = $element->nodeType == XML_ELEMENT_NODE ? '&lt;' . $element->nodeName . '&gt;' : $element->nodeName;
                    $this->handleError( self::ERROR_SCHEMA, ezpI18n::tr( 'kernel/classes/datatypes/ezxmltext', "%1 is not allowed to be a child of &lt;%2&gt;.",
                                        false, array( $elementName, $parent->nodeName ) ) );
                }
                $this->fixSubtree( $element, $element );
                return false;
            }
        }
        // TODO: break processing of any node that doesn't have parent
        //       and is not a root node.
        elseif ( $element->nodeName != 'section' )
        {
            return false;
        }
        return true;
    }
673766
public function validateBlocks(ElementInterface $element)
    {
        /** @var Element $element */
        /** @var SuperTableBlockQuery $value */
        $value = $element->getFieldValue($this->handle);

        foreach ($value->all() as $i => $block) {
            /** @var SuperTableBlock $block */
            if ($element->getScenario() === Element::SCENARIO_LIVE) {
                $block->setScenario(Element::SCENARIO_LIVE);
            }

            if (!$block->validate()) {
                foreach ($block->getErrors() as $attribute => $errors) {
                    $element->addErrors([
                        "{$this->handle}[{$i}].{$attribute}" => $errors,
                    ]);
                }
            }
        }
    }
1065610
protected function disableElementInArray($element, array &$itemList)
    {
        foreach ($itemList as $itemMarker => &$itemElements)
        {
            $itemElements = array_diff($itemElements, [$element]);
        }
    }
841153
private function loadValidatorElement(array &$property, ElementItem $element)
    {
        /* @var $element Element */
        $type = $element->getType();

        $attrs = [];
        $arrayized = strpos($property['type'], 'array<') === 0;

        if ($arrayized) {
            if ($itemOfArray = $this->isArrayNestedElement($type)) {
                $attrs = [
                    'min' => min($element->getMin(), $itemOfArray->getMin()),
                    'max' => $itemOfArray->getMax()
                ];
            }  elseif ($itemOfArray = $this->isArrayType($type)) {
                $attrs = [
                    'min' => min($element->getMin(), $itemOfArray->getMin()),
                    'max' => $itemOfArray->getMax()
                ];
            } elseif ($this->isArrayElement($element)) {
//                $attrs = [
//                    'min' => $element->getMin(),
//                    'max' => $element->getMax()
//                ];
            }
        }

        if (isset($attrs['min']) && $attrs['min'] === 0) {
            unset($attrs['min']);
        }
        if (isset($attrs['max']) && $attrs['max'] === -1) {
            unset($attrs['max']);
        }

        $rules = $this->loadValidatorType($property, $type, $arrayized );


        if ($element->getMin() > 0) {
            $property['validation'][] = [
                'NotNull' => null
            ];
        }

        if ($arrayized && count($attrs) > 0) {
            $property['validation'][] = [
                 'Count' => $attrs
            ];
        }
        if ($arrayized && count($rules) > 0) {
//            $rules[] = ['Valid' => null];
            $property['validation'][] = [
                'All' => ['constraints' => $rules]
            ];
        } elseif ($type instanceof ComplexType) {
            $property['validation'][] = [
                'Valid' => null
            ];
        }
    }
105884
protected function fillXml(\SimpleXMLElement $element, $data)
    {
        foreach ($data as $key => $value) {
            if (is_array($value) || is_object($value)) {
                if (!is_numeric($key)) {
                    $child = $element->addChild($key);
                } else {
                    $child = $element;
                }
                
                $this->fillXml($child, $value);
            } else {
                $element->addChild($key, $value);
            }
        }
    }
244875
public function addElement(BaseElement $element): ContainerElement
    {
        $element->parent = $this;
        $this->children[] = $element;
        if ($element instanceof ContainerElement) {
            return $element;
        }

        return $this;
    }
1293846
private function setData(array $data, ?bool $force = null) : void
    {
        $force = $force ?? false;

        /** @var DOMElement $node */
        foreach ($this->getNodeList() as $name => $node) {
            if (! array_key_exists($name, $data)) {
                // No value set for this element
                continue;
            }

            $value = $data[$name];

            $reuseSubmittedValue = filter_var(
                $node->getAttribute('data-reuse-submitted-value'),
                FILTER_VALIDATE_BOOLEAN
            );

            if (! $reuseSubmittedValue && $force === false) {
                // Don't need to set the value
                continue;
            }

            if (in_array($node->getAttribute('type'), ['checkbox', 'radio'], true)) {
                if ($value === $node->getAttribute('value')) {
                    $node->setAttribute('checked', 'checked');
                } else {
                    $node->removeAttribute('checked');
                }
            } elseif ($node->nodeName === 'select') {
                /** @var DOMElement $option */
                foreach ($node->getElementsByTagName('option') as $option) {
                    if ($value === $option->getAttribute('value')) {
                        $option->setAttribute('selected', 'selected');
                    } else {
                        $option->removeAttribute('selected');
                    }
                }
            } elseif ($node->nodeName === 'input') {
                // Set value for input elements
                $node->setAttribute('value', (string) $value);
            } elseif ($node->nodeName === 'textarea') {
                $node->nodeValue = $value;
            }
        }
    }
77695
protected function mapModelDataToElement(ElementInterface $child)
    {
        $this->setDefaultElementValue($child);
        
        $children = $child->getChildren();
        
        if ($children->count()) {
            $this->mapModelDataToElementCollection($children);
        }
    }
610920
private function walk(ElementStructure $elementStructure, $language, $masterLanguage)
    {
        $valueDatas = [];
        foreach ($elementStructure->getValues($language) as $value) {
            $valueData = [
                'id' => $value->getId(),
                'dsId' => $value->getDsId(),
                'name' => $value->getName(),
                'type' => $value->getType(),
                'content' => $value->getValue(),
                'attributes' => $value->getAttributes(),
                'options' => $value->getOptions(),
            ];
            if ($language !== $masterLanguage) {
                $masterValue = $elementStructure->getValue($value->getName(), $masterLanguage);
                if ($masterValue) {
                    $valueData['masterContent'] = $masterValue->getValue();
                }
            }
            $valueDatas[] = $valueData;
        }

        $structureDatas = [];
        foreach ($elementStructure->getStructures() as $subStructure) {
            $structureDatas[] = $this->walk($subStructure, $language, $masterLanguage);
        }

        $structureData = [
            //'id'         => $elementStructure->getId(),
            //'dataId'     => $elementStructure->getDataId(),
            'id' => $elementStructure->getDataId(),
            'dsId' => $elementStructure->getDsId(),
            'parentId' => $elementStructure->getParentId(),
            'parentDsId' => $elementStructure->getParentDsId(),
            'name' => $elementStructure->getName(),
            'parentName' => $elementStructure->getParentName(),
            'attributes' => $elementStructure->getAttributes(),
            'structures' => $structureDatas,
            'values' => $valueDatas,
        ];

        return $structureData;
    }