Helper method. Retrieves invalid elements from fieldset the $element belongs to.

@param ElementInterface $element
@param FieldsetInterface $fieldset
@return array|\Traversable
10410
protected function getInvalidFieldsetElements(ElementInterface $element, FieldsetInterface $fieldset)
    {
        $elementName = $this->normalizeElementName($element->getName());
        $elements = $fieldset->getElements();

        if (isset($elements[$elementName]) && $elements[$elementName] === $element) {
            if ($fieldset->getMessages()) {
                return $elements;
            }

            /* @var $fieldsetElement ElementInterface */
            foreach ($elements as $fieldsetElement) {
                if ($fieldsetElement->getMessages()
                    && ($fieldsetElement->getAttribute('type') === 'hidden'
                        || $fieldsetElement instanceof Element\Captcha)
                ) {
                    return $elements;
                }
            }
        }

        foreach ($fieldset->getFieldsets() as $fieldsetElement) {
            if ($elements = $this->getInvalidFieldsetElements($element, $fieldsetElement)) {
                return $elements;
            }
        }

        return [];
    }
115391
public function hasValidationErrors(FormRuntime $formRuntime, RootRenderableInterface $element): bool
    {
        return $this->getValidationResult($formRuntime, $element)->hasErrors();
    }
521488
public function render(ElementInterface $element): string
    {
        if (! $element instanceof DescriptionAwareInterface) {
            throw new InvalidClassException(
                sprintf(
                    'The given element "%s" does not implement "%s"',
                    $element->name(),
                    DescriptionAwareInterface::class
                )
            );
        }

        $description = $element->description();
        if ($description === '') {
            return '';
        }

        return sprintf(
            '<p %s>%s</p>',
            $this->attributesToString(
                [
                    'class' => 'form-row__description',
                ]
            ),
            $description
        );
    }
957454
public function validate(ErrorElement $errorElement, BlockInterface $block)
    {
        if (!$block->getId() && !$block->getType()) {
            return;
        }

        if ($this->inValidate) {
            return;
        }

        // As block can be nested, we only need to validate the main block, no the children
        try {
            $this->inValidate = true;
            $this->get($block)->validateBlock($errorElement, $block);
            $this->inValidate = false;
        } catch (\Exception $e) {
            $this->inValidate = false;
        }
    }
237693
protected function reflectCss( FieldsetInterface $fieldset, $selector )
    {
        foreach ( $fieldset->getFieldsets() as $subFieldset )
        {
            if ( ! $subFieldset instanceof Collection )
            {
                $this->reflectCss( $subFieldset, $selector );
            }
        }

        foreach ( $fieldset->getElements() as $name => $element )
        {
            $types = array_filter( preg_split( '/\s+/', trim(
                $element->getAttribute( 'data-js-type' )
            ) ) );

            $types[] = 'js.paragraph.reflectCss';

            $element->setAttributes( array(
                'data-js-type'                  => implode( ' ', $types ),
                'data-js-reflectcss-selector'   => $selector,
                'data-js-reflectcss-property'   => String::decamelize( $name ),
            ) );
        }

        return $fieldset;
    }
67074
public function parseElements(array $elements, ElementInterface $parent = null)
    {
        foreach ($elements as &$element) {
            $element = $this->applyStyles($element);
        }

        return parent::parseElements($elements, $parent);
    }
1063184
protected function getPropertyChildValue(\DOMElement $element, ContextInterface $context)
    {
        // If the property creates a new type: Return the element itself
        if ($element->hasAttribute('itemscope')) {
            $thing = $this->getThing($element->getAttribute('itemtype'), null, $context);
            return $this->processItemReferences($element, $context, $thing);
        }

        return null;
    }
948454
public function validateSegment($element, FormStateInterface $formState)
    {
        $originalValue = trim($formState->getValue('segment'));

        if (!empty($originalValue)) {

            $value = $this->seoService->normalizeSegment($originalValue);

            if ($originalValue !== $value) {
                $formState->setError(
                    $element,
                    $this->t(
                        "The alias '%alias' is invalid and has been normalized to: <strong>%normalized</strong>, please change the value below.",
                        ['%alias' => $originalValue, '%normalized' => $value]
                    )
                );
            }

            $formState->setValueForElement($element, $value);
        }
    }
559154
public function render(ElementInterface $element)
    {
        $attributes = $element->getAttributes();
        $captcha = $element->getCaptcha();

        if ($captcha === null || ! $captcha instanceof CaptchaAdapter) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the element has a "captcha" is an instance of LosReCaptcha\Captcha\ReCaptcha',
                __METHOD__
            ));
        }

        $name          = $element->getName();
        $id            = isset($attributes['id']) ? $attributes['id'] : $name;
        $responseName  = empty($name) ? 'recaptcha_response_field' : $name . '[recaptcha_response_field]';
        $responseId    = $id . '-response';

        $markup = $captcha->getService()->getHtml($name);
        $hidden = $this->renderHiddenInput($responseName, $responseId);
        $js     = $this->renderJsEvents($responseId);

        return $hidden . $markup . $js;
    }
1329363
public function render(ElementInterface $element)
    {
        $captcha = $element->getCaptcha();

        if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the element has a "captcha" attribute implementing Zend\Captcha\AdapterInterface',
                __METHOD__
            ));
        }

        $name = $element->getName();
        $id = $element->getAttribute('id') ? $element->getAttribute('id') : $name;

        $captchaPattern = '<div %s></div>';

        $captchaAttributes = $this->createAttributesString(array(
            'class' => 'g-recaptcha '.$element->getAttribute('class'),
            'data-sitekey' => $captcha->getSiteKey(),
            'data-theme' => $captcha->getTheme(),
            'data-type' => $captcha->getType(),
            'data-size' => $captcha->getSize(),
            'data-callback' => $captcha->getCallback(),
        ));


        $captchaElement = sprintf($captchaPattern, $captchaAttributes);
        $input = $this->renderHiddenInput($id, $name);
        $js = $this->renderJsCallback($captcha->getCallback(), $id);

        return $captchaElement . $input . $js;
    }
77149
protected function findByNameOrId($name, $element = '*')
    {
        $name = str_replace('#', '', $name);

        try {
            return $this->session->element('css selector', "#{$name}, *[name={$name}]");
        } catch (NoSuchElement $e) {
            throw new InvalidArgumentException(
                "Couldn't find an element, '{$element}', with a name or class attribute of '{$name}'."
            );
        }
    }
187625
private static function askRequiredValue(StyleInterface $io, ContextElement $element, $emptyValue)
    {
        if (null === $emptyValue) {
            return $element->askString($io);
        }

        if (false === $emptyValue) {
            return $element->askBool($io);
        }

        if ([] === $emptyValue) {
            return $element->askIterable($io);
        }

        return $emptyValue;
    }
91940
public function render(ElementInterface $element): string
    {
        if (! $element instanceof FormInterface) {
            throw new InvalidClassException(
                sprintf(
                    'The given element "%s" has to implement "%s"',
                    $element->name(),
                    FormInterface::class
                )
            );
        }

        $row = $this->factory->create(FormRow::class);

        $html = array_reduce(
            $element->elements(),
            function ($html, ElementInterface $next) use ($element, $row) {
                $html .= $row->render($next);

                return $html;
            },
            ''
        );

        $errors = $element instanceof ErrorAwareInterface
            ? $this->factory->create(Errors::class)
                ->render($element)
            : '';

        $class = $errors !== ''
            ? 'form-table--has-errors'
            : '';

        $html = sprintf('%1$s <table class="form-table %2$s">%3$s</table>', $errors, $class, $html);

        return sprintf(
            '<form %s>%s</form>',
            $this->attributesToString($element->attributes()),
            $html
        );
    }
1140831
protected function renderType(ElementInterface $element)
    {
        $type = $element->getAttribute('type');

        if (isset($this->typeMap[$type])) {
            return $this->renderHelper($this->typeMap[$type], $element);
        }
        return null;
    }
570356
public function convert(ElementInterface $element)
    {
        // If parent is an ol, use numbers, otherwise, use dashes
        $tagname = $element->getParent()->getTagName();

        // Add spaces to start for nested list items
        $level = $element->getListItemLevel($element);

        $items = explode("\n", trim($element->getValue()));

        $paragraphPrefix = str_repeat('  ', $level + 1);

        $value = implode("\n" . $paragraphPrefix, $items);

        $number = (integer) $element->getSiblingPosition();

        // If list item is the first in a nested list, add a newline before it
        $prefix = $level > 0 && $number === 1 ? "\n" : '';

        $position = $tagname === 'ol' ? $number . '. ' : '* ';

        return $prefix . $position . trim($value) . "\n";
    }
695767
protected function isElementHasError(ElementInterface $element, FormInterface $form)
    {
        if ($element->getMessages()) {
            return true;
        }

        $elementName = $this->normalizeElementName($element->getName());
        $elements = $this->getInvalidFieldsetElements($element, $form);
        if (isset($elements[$elementName]) && $elements[$elementName] === $element) {
            return true;
        }

        return false;
    }
579878
public function afterElementDelete (ElementInterface $element)
	{
		SimpleMap::getInstance()->map->softDeleteField($this, $element);
		parent::afterElementDelete($element);
	}