io-8.x-1.x-dev/modules/io_browser/io_browser.module

modules/io_browser/io_browser.module
<?php

/**
 * @file
 * Provides a Io Entity Browser integration.
 */

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\WidgetInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\io_browser\IoBrowserDefault;

/**
 * Provides a convenient shortcut for procedural hooks.
 *
 * @param string $key
 *   Identifier of the service.
 *
 * @return \Drupal\io_browser\IoBrowser
 *   |\Drupal\io_browser\IoBrowserWidget
 *   The required IO Browser class instance.
 */
// @codingStandardsIgnoreStart
function io_browser($key = 'manager') {
  static $manager;
  static $widget;

  if (!isset($manager)) {
    $manager = \Drupal::service('io_browser');
    $widget = \Drupal::service('io_browser.widget');
  }

  switch ($key) {
    case 'widget':
      return $widget;

    default:
      return $manager;
  }
}
// @codingStandardsIgnoreEnd

/**
 * Implements hook_theme().
 */
function io_browser_theme() {
  return [
    'io_browser' => [
      'render element' => 'element',
      'file' => 'templates/io_browser.theme.inc',
    ],
  ];
}

/**
 * Overrides hook_preprocess_views_view().
 */
function io_browser_preprocess_views_view(&$variables) {
  io_browser()->preprocessViewsView($variables);
}

/**
 * Overrides hook_preprocess_blazy().
 */
function io_browser_preprocess_blazy(&$variables) {
  $settings = &$variables['settings'];
  if (io_browser()->isApplicable($settings)) {
    io_browser()->preprocessBlazy($variables);
  }
}

/**
 * Implements hook_blazy_alter().
 */
function io_browser_blazy_alter(array &$build, array $settings) {
  if (io_browser()->isApplicable($settings)) {
    $build['#build']['settings']['noscript'] = FALSE;
    $build['#build']['settings']['fx'] = '';
  }
}

/**
 * Implements hook_blazy_settings_grid_alter().
 */
function io_browser_blazy_settings_grid_alter(array &$settings) {
  if (io_browser()->isApplicable($settings)) {
    $blazies = $settings['blazies'];

    if ($blazies->is('grid')) {
      $attrs['class'][] = 'ib__grid';
      $item_attrs['class'][] = 'grid--ib';

      $blazies->set('grid.attributes', $attrs);
      $blazies->set('grid.item_attributes', $item_attrs);
    }
  }
}

/**
 * Implements hook_form_alter().
 */
function io_browser_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
  if (isset($form['#browser_parts'])
    && strpos($form_id, 'io_browser') !== FALSE) {
    /* @phpstan-ignore-next-line */
    io_browser('widget')->formAlter($form, $form_state, $form_id);
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function io_browser_form_views_ui_add_handler_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
  /* @phpstan-ignore-next-line */
  io_browser('widget')->formViewsUiAddHandlerFormAlter($form, $form_state, $form_id);
}

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function io_browser_field_widget_complete_form_alter(&$form, FormStateInterface $form_state, $context) {
  $element = &$form['widget'];
  /* @phpstan-ignore-next-line */
  io_browser('widget')->fieldWidgetFormAlter($element, $form_state, $context);
}

/**
 * Implements hook_field_widget_third_party_settings_form().
 */
function io_browser_field_widget_third_party_settings_form(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state) {
  if (in_array($plugin->getPluginId(), IoBrowserDefault::thirdPartyWidgets())) {
    /* @phpstan-ignore-next-line */
    return io_browser('widget')->widgetThirdPartySettingsForm($plugin, $field_definition, $form_mode, $form, $form_state);
  }
  return [];
}

/**
 * Implements hook_form_views_exposed_form_alter().
 */
function io_browser_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) {
  /* @phpstan-ignore-next-line */
  io_browser('widget')->formViewsExposedFormAlter($form, $form_state);
}

/**
 * Implements hook_config_schema_info_alter().
 */
function io_browser_config_schema_info_alter(array &$definitions) {
  blazy()->configSchemaInfoAlter($definitions, 'io_browser', IoBrowserDefault::extendedSettings());
}

/**
 * Implements hook_help().
 */
function io_browser_help($route_name) {
  if ($route_name == 'help.page.io_browser') {
    $output = file_get_contents(dirname(__FILE__) . '/README.md');
    return blazy()->markdown($output);
  }
  return '';
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc