You are here

wingsuit_ui_patterns.module in Gin Layout Builder 8.2

Contains ui patterns hooks.

File

modules/wingsuit_ui_patterns/wingsuit_ui_patterns.module
View source
<?php

/**
 * @file
 * Contains ui patterns hooks.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Hide all none ui patterns layouts.
 *
 * Implements hook_plugin_filter_TYPE_alter().
 */
function wingsuit_ui_patterns_plugin_filter_layout_alter(array &$definitions, array $extra, $consumer) {
  $use_only_wingsuit_layouts = \Drupal::configFactory()
    ->get('wingsuit_companion.config')
    ->get('only_own_layout');

  /**
   * @var string $key
   * @var \Drupal\Core\Layout\LayoutDefinition $definition
   */
  foreach ($definitions as $key => $definition) {
    if ($definition
      ->getProvider() !== 'wingsuit' && $use_only_wingsuit_layouts === TRUE) {
      unset($definitions[$key]);
    }
  }
}

/**
 * Handles visibility property in patterns.
 *
 * Implements hook_ui_patterns_info_alter().
 */
function wingsuit_ui_patterns_ui_patterns_info_alter(&$definitions) {

  /**
   * @var $key
   * @var \Drupal\ui_patterns\Definition\PatternDefinition $definition
   */
  foreach ($definitions as $key => $definition) {
    $additional = $definition
      ->getAdditional();
    if (isset($additional['visibility'])) {
      $apps = array_map('trim', explode('|', $additional['visibility']));
      if (!in_array('drupal', $apps)) {
        unset($definitions[$key]);
      }
    }
  }
}

/**
 * Implements hook_help().
 */
function wingsuit_ui_patterns_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the wingsuit_companion module.
    case 'help.page.wingsuit_companion':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This module add UI Patterns support to Wingsuit.') . '</p>';
      return $output;
    default:
  }
}

Functions

Namesort descending Description
wingsuit_ui_patterns_help Implements hook_help().
wingsuit_ui_patterns_plugin_filter_layout_alter Hide all none ui patterns layouts.
wingsuit_ui_patterns_ui_patterns_info_alter Handles visibility property in patterns.