public function BlockPluginUI::form

Overrides \Drupal\system\Plugin\PluginUIBase::form().

@todo Add inline documentation to this method.

Overrides PluginUIBase::form

File

drupal/core/modules/block/lib/Drupal/block/Plugin/PluginUI/BlockPluginUI.php, line 45

Class

BlockPluginUI
Defines an overrideable UI for block selection, configuration, and placement.

Namespace

Drupal\block\Plugin\PluginUI

Code

public function form($form, &$form_state, $facet = NULL) {

  // @todo Add an inline comment here.
  list($plugin, $theme) = explode(':', $this
    ->getPluginId());
  $plugin_definition = $this
    ->getPluginDefinition();

  // @todo Find out how to let the manager be injected into the class.
  $manager = drupal_container()
    ->get($plugin_definition['manager']);
  $plugins = $manager
    ->getDefinitions();
  $form['#theme'] = 'system_plugin_ui_form';
  $form['theme'] = array(
    '#type' => 'value',
    '#value' => $theme,
  );
  $form['manager'] = array(
    '#type' => 'value',
    '#value' => $manager,
  );
  $form['instance'] = array(
    '#type' => 'value',
    '#value' => $this,
  );
  $form['right']['block'] = array(
    '#type' => 'textfield',
    '#title' => t('Search'),
    '#autocomplete_path' => 'system/autocomplete/' . $this
      ->getPluginId(),
  );
  $form['right']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Next'),
  );
  $rows = array();
  foreach ($plugins as $plugin_id => $display_plugin_definition) {
    if (empty($facet) || $this
      ->facetCompare($facet, $display_plugin_definition)) {
      $rows[$plugin_id] = $this
        ->row($plugin_id, $display_plugin_definition);
    }
    foreach ($plugin_definition['facets'] as $key => $title) {
      $facets[$key][$display_plugin_definition[$key]] = $this
        ->facetLink($key, $plugin_id, $display_plugin_definition);
    }
    $form['right']['all_plugins'] = array(
      '#type' => 'link',
      '#title' => $plugin_definition['all_plugins'],
      '#href' => $this
        ->allPluginsUrl($plugin_id, $display_plugin_definition),
    );
    foreach ($facets as $group => $values) {
      $form['right'][$group] = array(
        '#theme' => 'links',
        '#heading' => array(
          'text' => $plugin_definition['facets'][$group],
          'level' => 'h3',
        ),
        '#links' => $values,
      );
    }
  }

  // Sort rows alphabetically.
  asort($rows);
  $form['left']['plugin_library'] = array(
    '#theme' => 'table',
    '#header' => $this
      ->tableHeader(),
    '#rows' => $rows,
  );
  return $form;
}