Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / src / Element / InfoElement.php
Size: Mime:
<?php

namespace Drupal\custom_forms\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Template\Attribute;

/**
 * Class InfoElement
 *
 * @package Drupal\custom_forms\Element
 *
 * @RenderElement("info_element")
 */
class InfoElement extends RenderElement {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return [
      '#theme' => 'field_info',
      '#input' => FALSE,
      '#pre_render' => [
        [__CLASS__, 'preRenderInfoElement'],
      ],
      '#title_display' => 'invisible',
      '#icon' => NULL,
      '#message' => NULL,
      '#weight' => 1000
    ];
  }

  public static function preRenderInfoElement(array $element) : array {
    $attributes = new Attribute();
    $attributes->addClass('field-info');

    $icon_attributes = new Attribute();
    $icon_attributes->addClass('icon');

    $message_attributes = new Attribute();
    $message_attributes->addClass('message');


    $element['#attributes'] = $attributes;
    $element['#icon_attributes'] = $icon_attributes;
    $element['#message_attributes'] = $message_attributes;

    return $element;
  }
}