Given element category, create a collapsible icon and
course header.

@param array $element
@return string HTML
544255
protected function get_course_header($element) {
        global $OUTPUT;

        $icon = '';
        // If object is a category, display expand/contract icon.
        if ($element['type'] == 'category') {
            // Load language strings.
            $strswitchminus = $this->get_lang_string('aggregatesonly', 'grades');
            $strswitchplus  = $this->get_lang_string('gradesonly', 'grades');
            $strswitchwhole = $this->get_lang_string('fullmode', 'grades');

            $url = new moodle_url($this->gpr->get_return_url(null, array('target' => $element['eid'], 'sesskey' => sesskey())));

            if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) {
                $url->param('action', 'switch_plus');
                $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $strswitchplus), null, null);
                $showing = get_string('showingaggregatesonly', 'grades');
            } else if (in_array($element['object']->id, $this->collapsed['gradesonly'])) {
                $url->param('action', 'switch_whole');
                $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_whole', $strswitchwhole), null, null);
                $showing = get_string('showinggradesonly', 'grades');
            } else {
                $url->param('action', 'switch_minus');
                $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $strswitchminus), null, null);
                $showing = get_string('showingfullmode', 'grades');
            }
        }

        $name = $element['object']->get_name();
        $courseheaderid = 'courseheader_' . clean_param($name, PARAM_ALPHANUMEXT);
        $courseheader = html_writer::tag('span', $name, array('id' => $courseheaderid,
                'title' => $name, 'class' => 'gradeitemheader'));
        $courseheader .= html_writer::label($showing, $courseheaderid, false, array('class' => 'accesshide'));
        $courseheader .= $icon;

        return $courseheader;
    }
1060944
public static function processElement(array $element) {
    $settings = \Drupal::configFactory()->get('openy_map.settings');
    $element['#attached']['library'][] = 'openy_map/openy_map';
    switch ($settings->get('map_engine')) {
      case 'gmaps':
        $element['#attached']['library'][] = 'openy_map/gmaps';
        $element['#attached']['drupalSettings']['openyMapSettings']['engine'] = 'gmaps';
      break;

      case 'leaflet':
      default:
        $element['#attached']['library'][] = 'openy_map/leaflet';
        $mapSettings = &$element['#attached']['drupalSettings']['openyMapSettings'];
        $mapSettings['engine'] = 'leaflet';
        $mapSettings['default_location'] = urlencode(trim(_openy_map_get_default_location()));
        $mapSettings['search_icon'] = $settings->get('leaflet.search_icon');
        $mapSettings['search_icon_retina'] = $settings->get('leaflet.search_icon_retina');
        $mapSettings['base_layer'] = $settings->get('leaflet.base_layer');
      break;
    }
    $element['#attached']['drupalSettings']['openyMap'] = $element['#element_variables'];
    $tags = $settings->get('default_tags');
    $element['#attached']['drupalSettings']['openyMapSettings']['default_tags'] = array_values(array_filter($tags));
    $element['#cache']['tags'][] = 'config:openy_map.settings';

    return $element;
  }
437721
public function addElement(Element $element)
    {
        if (!in_array($element, $this->elements, true)) {
            array_push($this->elements, $element);
        }
        return $this;
    }
409300
protected function getBlock(\DOMElement $element) {
    $block = '';
    /** @var \DOMNode $node */
    foreach ($element->childNodes as $node) {
      switch ($node->nodeType) {

        case XML_ELEMENT_NODE:
          /** @var \DOMElement $node */
          switch ($node->nodeName) {

            // Explicitly handle these elements.

            case 'i':
            case 'em':
              $block .= '*' . $this->getBlock($node) . '*';
              break;

            case 'b':
            case 'strong':
              $block .= '**' . $this->getBlock($node) . '**';
              break;

            case 'a':
              if ($node->hasAttribute('href')) {
                $block .= '[' . $this->getBlock($node) . ']' .
                  '(' . $node->getAttribute('href') . ')';
              }
              break;

            // Other inline elements.
            default:
              // Recursively handle any descendant elements we care about.
              $block .= $this->getBlock($node);
              break;

          }
          break;

        case XML_TEXT_NODE:
          /** @var \DOMText $node */
          $block .= self::escape($node->textContent);
          break;

      }
    }

    // Handle white-listed elements.
    if (in_array($element->nodeName, $this->white_list)) {
      $tag = $element->cloneNode();
      if (!empty($block)) {
        $tag->appendChild(new \DOMText($block));
      }
      $block = $this->dom->saveXML($tag);
    }

    return $block;
  }
1291408
public function generatePluginHtml(array $element, $configContext)
    {
        if ($element['i18n'] && $configContext !== self::TYPE_LIST) {

            return $this->view->render('_crudform_i18n_pluginhtml', [
                'element' => $element,
                'configContext' => $configContext,
                'languages' => Lang::getQuery(),
                'helpButtonHtml' => $this->createFieldHelpButton($element, $configContext),
            ]);
        }   

        $ngModel = $this->ngModelString($configContext, $element['name']);

        return $this->createFieldHelpButton($element, $configContext) . 
            $this->renderElementPlugins($configContext, $element['type'], Inflector::slug($ngModel), $element['name'], $ngModel, $element['alias'], false);
    }
1143677
protected function _singleElement($element, $attributes = [])
    {
        $perm = $this->settings['attr']['perm'] ?? NULL;

        $this->outputElement .= $this->_perm($perm, '<'.strtolower($element).$this->attributes($attributes).'>');

        return $this;
    }
301172
protected function formatFormElement(array $element)
    {
        $sm = $this->getServiceLocator();
        $result = array();
        if (array_key_exists('lazy-set', $element)) {
            $result = $sm->get($this->moduleService)->lazySet($element['lazy-set']);
        }
        $result['name'] = $element['name'];
        $result['type'] = $element['type'];
        if (array_key_exists('label', $element)) {
            $result['options']['label'] = $element['label'];
        }
        return $result;
    }
34408
public static function getTagByHandle($element)
    {
        $group = Craft::$app->tags->getTagGroupByHandle($element['group']);
        if ($group) {

            $query = Tag::find();
            $query->groupId($group->id);
            $query->slug($element['slug']);
            $tag = $query->one();

            if ($tag) {
                return $tag;
            }
        }
    }
1230996
private function mapNode(\DOMElement $element)
    {
        $attributes = [];

        $titles = [];
        $titlesElement = $element->getElementsByTagName('titles')->item(0);
        foreach ($titlesElement->getElementsByTagName('title') as $titleNode) {
            $titles[$titleNode->getAttribute('language')] = $titleNode->textContent;
        }

        $slugs = [];
        $slugsElement = $element->getElementsByTagName('slugs')->item(0);
        foreach ($slugsElement->getElementsByTagName('slug') as $slugNode) {
            $slugs[$slugNode->getAttribute('language')] = $slugNode->textContent;
        }

        $versions = [];
        $versionsElement = $element->getElementsByTagName('versions')->item(0);
        foreach ($versionsElement->getElementsByTagName('version') as $versionNode) {
            $versions[$versionNode->getAttribute('language')] = (int) $versionNode->textContent;
        }

        $node = new ContentTreeNode();
        $node
            ->setTree($this)
            ->setId((int) $element->getAttribute('id'))
            ->setParentNode($element->getAttribute('parentId') ? (int) $element->getAttribute('parentId') : null)
            ->setType((string) $element->getAttribute('type'))
            ->setTypeId((int) $element->getAttribute('typeId'))
            ->setAttributes($attributes)
            ->setSort((string) $element->getAttribute('sort'))
            ->setSortMode((string) $element->getAttribute('sortMode'))
            ->setSortDir((string) $element->getAttribute('sortDir'))
            ->setTitles($titles)
            ->setSlugs($slugs)
            //->setVersions($versions)
            ->setCreatedAt(new \DateTime((string) $element->getAttribute('createdAt')))
            ->setCreateUserId((string) $element->getAttribute('createUserId'));

        $this->nodes[$node->getId()] = $node;

        if ($node->getParentNode() === null) {
            $this->rootId = $node->getId();
        }

        return $node;
    }
1127120
public function addBlankElement($element)
    {
        if (!isset($this->info[$element])) {
            $this->elements[] = $element;
            $this->info[$element] = new HTMLPurifier_ElementDef();
            $this->info[$element]->standalone = false;
        } else {
            trigger_error("Definition for $element already exists in module, cannot redefine");
        }
        return $this->info[$element];
    }
1266127
protected function applyStyles($element)
    {
        if ( ! $this->style) return $element;

        if (array_key_exists('class', $element['attributes'])) {
            $classes = explode(' ', $element['attributes']['class']);
            $element = $this->applyStylesToElement($element, $this->style->getByClasses($classes));
        }

        if (array_key_exists('id', $element['attributes'])) {
            $element = $this->applyStylesToElement($element, $this->style->getById($element['attributes']['id']));
        }

        $element = $this->applyStylesToElement($element, $this->style->getByElement($element['name']));

        return $element;
    }
847792
protected function exportHtml(\DOMElement $element)
    {
        $body = $this->getDocument()->createElement('body');
        $body->appendChild($element);
        $html = $this->getDocument()->getElementsByTagName('html')->item(0);
        $html->appendChild($this->getHead());
        $html->appendChild($body);

        $html =  $this->getDocument()->saveHTML();
        $this->reset();

        return $html;
    }
308752
private function wrap($element) {
        $this->stack[] = $this->data;
        foreach ($element as $k => $v) {
            $this->data[$k] = $v;
        }
    }
1261099
public function label(Form\Element\Label $element)
    {
        $html = '<label class="col-md-3 control-label">' . $element->getLabel() . '</label>';
        $html .= '<div class="col-md-9"><p class="form-control-static">' . $element->getValue() . '</p></div>';

        $class =  Style::FORM_GROUP_CLASS . ' row';
        return html('div', compact('class'), $html);
    }
1126056
public function render(Element $element)
    {
        // For all non-checkbox fields...
        if ($element instanceof AbstractFormField && !$element instanceof CheckBox) {
            if (!$element->getId()) {
                $element->setId('field-' . uniqid());
            }

            // Render our label
            $label = new Tag('label');
            $label->setAttribute('for', $element->getId());
            $label->setInnerHtml($element->getTitle());

            // If no labels are wanted, we set it to "Screen Reader" only,
            // @see http://getbootstrap.com/css/#callout-inline-form-labels
            if ($this->mode == self::MODE_INLINE_NO_LABELS) {
                $label->setAttribute('class', 'sr-only');
            }

            // Render our field, but with an css class "form-control"
            $element->addClass('form-control');
            $field = parent::render($element);

            // Render a help block if an help-text is set.
            $helpBlock = '';
            if ($element->getHelpText()) {
                $helpTag = new Tag('p');
                $helpTag->setAttribute('class', 'help-block');
                $helpTag->setInnerHtml($element->getHelpText());
                $helpBlock = $helpTag->render();
            }

            // Now render our container div, which will contain all of the above
            $tag = new Tag('div');
            $cssClass = 'form-group';

            if ($element->getForm()->isSubmitted()) {
                if (!$element->isValid()) {
                    $cssClass .= ' has-error has-feedback';
                } else {
                    $cssClass .= ' has-success has-feedback';
                }
            }

            $tag->setAttribute('class', $cssClass);

            $tag->setInnerHtml(
                $label->render() . PHP_EOL .
                $field . PHP_EOL .
                $helpBlock . PHP_EOL
            );

            return $tag->render();

        } elseif ($element instanceof AbstractFormButton) {
            $element->addClass('btn');

            $buttons = $element->getForm()->getFieldsByClass('\FormHandler\Field\AbstractFormButton');
            if (sizeof($buttons) == 1) {
                $element->addClass('btn-primary');
            }

            return parent::render($element);
        }
        return parent::render($element);
    }
368267
private function renderElement(Element $element) : string
    {
        $label = $element->getLabel();

        if ($label->isEmpty()) {
            return $element->render();
        }

        return $label->render() . $element->render();
    }
521701
public function formSelect(IMultiElement $element)
    {
        $attributes = $this->buildAttributes($element->getAttributes());
        $html = '<select ' . $attributes . ' value="' . $element->getValue() . '">';

        foreach ($element->getChoices() as $value => $label) {
            $attr = ['value' => $value];

            if ($value == $element->getValue()) {
                $attr += [
                    'selected' => 'selected'
                ];
            }

            $html .= '<option ' . $this->buildAttributes(new \ArrayObject($attr)) . '>' . $label . '</option>';
        }

        $html .= '</select>';

        return $html;
    }