ercore-8.x-1.20/modules/ercore_summary_views/ercore_summary_views.module

modules/ercore_summary_views/ercore_summary_views.module
<?php

/**
 * @file
 * Module file for ercore_summary_views.
 */

use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Alters the Institutions options on Summary views.
 */
function ercore_summary_views_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // This is not the view you are looking, move along.
  $form_ids = [
    'views-exposed-form-ercore-summary-of-collaborations-page-1',
    'views-exposed-form-ercore-summary-of-events-page-1',
    'views-exposed-form-ercore-summary-of-external-collaborators-page-1',
    'views-exposed-form-ercore-summary-of-external-engagements-page-1',
    'views-exposed-form-ercore-summary-of-highlights-page-1',
    'views-exposed-form-ercore-summary-of-honors-page-1',
    'views-exposed-form-ercore-summary-of-other-research-products-page-1',
    'views-exposed-form-ercore-summary-of-participants-page-1',
    'views-exposed-form-ercore-summary-of-patents-page-1',
    'views-exposed-form-ercore-summary-of-presentations-page-1',
    'views-exposed-form-ercore-summary-of-proposals-and-grants-page-1',
    'views-exposed-form-ercore-summary-of-publications-page-1',
  ];
  if (!in_array($form['#id'], $form_ids)) {
    return FALSE;
  }
  $options = ercore_get_institutions();
  if (!empty($options)) {
    // Start building out our new form element.
    $inst_field = 'field_ercore_user_partic_inst_target_id';
    // External collaborators uses different Institution field.
    if ($form['#id'] === 'views-exposed-form-ercore-summary-of-external-collaborators-page-1') {
      $inst_field = 'field_ercore_cr_inst_target_id';
    }
    $form[$inst_field]['#type'] = 'select';
    $form[$inst_field]['#multiple'] = FALSE;

    // Specify the empty option for our select list.
    $form[$inst_field]['#empty_option'] = t('Institution');

    // Add the $options from above to our select list.
    $form[$inst_field]['#options'] = $options;
    unset($form[$inst_field]['#size']);
  }
}

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

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