You are here

public static function ModuleFilter::processModuleFilter in Module Filter 8

#process callback for #modulefilter form element property.

Parameters

array $element: An associative array containing the properties and children of the generic input element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

Return value

array The processed element.

File

src/Element/ModuleFilter.php, line 69
Contains \Drupal\module_filter\Element\ModuleFilter.

Class

ModuleFilter
Provides a one-line text field form element.

Namespace

Drupal\module_filter\Element

Code

public static function processModuleFilter(&$element, FormStateInterface $form_state, &$complete_form) {
  $config = \Drupal::config('module_filter.settings');
  $module_handler = \Drupal::moduleHandler();
  $element['name'] = array(
    '#type' => 'textfield',
    '#title' => isset($element['#title']) ? $element['#title'] : t('Filter list'),
    '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : (isset($_GET['filter']) ? $_GET['filter'] : ''),
    '#size' => isset($element['#size']) ? $element['#size'] : 45,
    '#weight' => isset($element['#weight']) ? $element['#weight'] : -10,
    '#attributes' => (isset($element['#attributes']) ? $element['#attributes'] : array()) + array(
      'autocomplete' => 'off',
    ),
    '#attached' => array(
      'library' => array(
        'module_filter/drupal.module_filter',
      ),
      'drupalSettings' => array(
        'moduleFilter' => array(
          'setFocus' => $config
            ->get('module_filter_set_focus'),
          'tabs' => $config
            ->get('module_filter_tabs'),
          'countEnabled' => $config
            ->get('module_filter_count_enabled'),
          'visualAid' => $config
            ->get('module_filter_visual_aid'),
          'hideEmptyTabs' => $config
            ->get('module_filter_hide_empty_tabs'),
          'dynamicPosition' => !$module_handler
            ->moduleExists('page_actions') ? $config
            ->get('module_filter_dynamic_save_position') : FALSE,
          'useURLFragment' => $config
            ->get('module_filter_use_url_fragment'),
          'useSwitch' => $config
            ->get('module_filter_use_switch'),
          'trackRecent' => $config
            ->get('module_filter_track_recent_modules'),
          'rememberActiveTab' => $config
            ->get('module_filter_remember_active_tab'),
          'rememberUpdateState' => $config
            ->get('module_filter_remember_update_state'),
        ),
      ),
    ),
  );
  if (isset($element['#description'])) {
    $element['name']['#description'] = $element['#description'];
  }
  return $element;
}