file_browser-8.x-1.3/file_browser.module

file_browser.module
<?php

/**
 * @file
 * Contains hook implementations for file_browser.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_help().
 */
function file_browser_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the file_browser module.
    case 'help.page.file_browser':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provides an entity browser for files.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_form_alter().
 */
function file_browser_form_alter(&$form, FormStateInterface &$form_state) {
  if (isset($form['#form_id'])) {
    if ($form['#form_id'] == 'entity_browser_browse_files_form' ||
        $form['#form_id'] == 'entity_browser_browse_files_modal_form') {
      file_browser_attach_file_browser_to_form($form);
    }
  }
}

/**
 * Attach the file_browser functionality into a form.
 *
 * @param array $form
 *   Nested array of form elements that comprise the form.
 */
function file_browser_attach_file_browser_to_form(array &$form) {
  // Attach our library.
  $form['#attached']['library'][] = 'file_browser/view';
  $form['#attached']['library'][] = 'file_browser/dropzone_css';

  if (isset($form['selection_display'])) {
    $form['selection_display']['#type'] = 'container';
    $form['selection_display']['#attributes']['class'] = ['file-browser-actions'];
  }

  if (!empty($form['widget']['actions'])) {
    $form['widget']['actions']['#attributes']['class'] = ['file-browser-actions'];
  }

  // Add a class for generic styling.
  $form['#attributes']['class'][] = 'file-browser-form';
}

/**
 * Implements hook_preprocess_details().
 */
function file_browser_preprocess_details(&$variables) {
  if (isset($variables['element']['#id']) && $variables['element']['#id'] == 'edit-field-file-browser-reference') {
    $variables['#attached']['library'][] = 'file_browser/iframe';
  }
}

/**
 * Implements hook_library_info_alter().
 */
function file_browser_library_info_alter(&$libraries, $extension) {
  // Optionally use the Libraries module to determine our library paths.
  if ($extension == 'file_browser' && \Drupal::moduleHandler()->moduleExists('libraries')) {
    // Use the library.libraries_directory_file_finder service if available.
    if (\Drupal::hasService('library.libraries_directory_file_finder')) {
      $backbone_lib_path = \Drupal::service('library.libraries_directory_file_finder')->find('backbone');
      $underscore_lib_path = \Drupal::service('library.libraries_directory_file_finder')->find('underscore');
      $imagesloaded_lib_path = \Drupal::service('library.libraries_directory_file_finder')->find('imagesloaded');
      $masonry_lib_path = \Drupal::service('library.libraries_directory_file_finder')->find('masonry');

      if ($backbone_lib_path) {
        $backbone_path = $backbone_lib_path . '/backbone-min.js';
        $libraries['backbone']['js'] = ['/' . $backbone_path => ['minified' => 'true']];
      }

      if ($underscore_lib_path) {
        $underscore_path = $underscore_lib_path . '/underscore-min.js';
        $libraries['underscore']['js'] = ['/' . $underscore_path => ['minified' => 'true']];
      }

      if ($imagesloaded_lib_path) {
        $imagesloaded_path = $imagesloaded_lib_path . '/imagesloaded.pkgd.min.js';
        $libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']];
      }

      if ($masonry_lib_path) {
        $masonry_path = $masonry_lib_path . '/dist/masonry.pkgd.min.js';
        $libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']];
      }
    }
  }
}

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

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