You are here

class PatternLayoutBuilder in UI Patterns Layout Builder 8

Same name in this branch
  1. 8 src/Element/PatternLayoutBuilder.php \Drupal\ui_patterns_layout_builder\Element\PatternLayoutBuilder
  2. 8 src/Plugin/Layout/PatternLayoutBuilder.php \Drupal\ui_patterns_layout_builder\Plugin\Layout\PatternLayoutBuilder

Renders a pattern element.

Hierarchy

Expanded class hierarchy of PatternLayoutBuilder

File

src/Element/PatternLayoutBuilder.php, line 13

Namespace

Drupal\ui_patterns_layout_builder\Element
View source
class PatternLayoutBuilder implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'processLayoutBuilderRegions',
    ];
  }

  /**
   * Process layout builder regions.
   *
   * Layout builder adds foreach region an renderable array
   * after the pattern is built. So reassign the region to fields.
   *
   * @param array $element
   *   Render array.
   *
   * @return array
   *   Render array.
   */
  public static function processLayoutBuilderRegions(array $element) {
    $definiton = UiPatterns::getPatternDefinition($element['#id']);
    if ($definiton != NULL) {
      foreach (Element::children($element) as $key) {
        if ($definiton
          ->hasField($key)) {
          $region_children = Element::children($element[$key]);
          $region_properties = Element::properties($element[$key]);
          if (isset($element['#' . $key]) && is_string($element['#' . $key])) {
            continue;
          }
          foreach ($region_children as $region_key) {
            $element['#' . $key][$region_key] = $element[$key][$region_key];
          }
          foreach ($region_properties as $property_key) {
            if ($property_key === '#attributes') {
              $element['#region_attributes'][$key] = new Attribute($element[$key][$property_key]);
            }
          }

          // Disabled unset region key. Region Used in quick edit.
          // unset($element[$key]);.
        }
      }
    }
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PatternLayoutBuilder::processLayoutBuilderRegions public static function Process layout builder regions.
PatternLayoutBuilder::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.