class BlockPluginUI extends PluginUIBase {
public function form($form, &$form_state, $facet = NULL) {
list($plugin, $theme) = explode(':', $this
->getPluginId());
$plugin_definition = $this
->getPluginDefinition();
$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,
);
}
}
asort($rows);
$form['left']['plugin_library'] = array(
'#theme' => 'table',
'#header' => $this
->tableHeader(),
'#rows' => $rows,
);
return $form;
}
public function formValidate($form, &$form_state) {
$definitions = $form_state['values']['manager']
->getDefinitions();
if (!isset($definitions[$form_state['values']['block']])) {
form_set_error('block', t('You must select a valid block.'));
}
}
public function formSubmit($form, &$form_state) {
$form_state['redirect'] = 'admin/structure/block/add/' . $form_state['values']['block'] . '/' . $form_state['values']['theme'];
}
public function access() {
list($plugin, $theme) = explode(':', $this
->getPluginId());
return _block_themes_access($theme);
}
public function tableHeader() {
return array(
t('Subject'),
t('Operations'),
);
}
public function row($display_plugin_id, array $display_plugin_definition) {
$plugin_definition = $this
->getPluginDefinition();
list($plugin, $theme) = explode(':', $this
->getPluginId());
$row = array();
$row[] = check_plain($display_plugin_definition['admin_label']);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => array(
'configure' => array(
'title' => $plugin_definition['link_title'],
'href' => $plugin_definition['config_path'] . '/' . $display_plugin_id . '/' . $theme,
),
),
),
);
return $row;
}
protected function facetLink($facet, $display_plugin_id, array $display_plugin_definition) {
$plugin_definition = $this
->getPluginDefinition();
return array(
'title' => $display_plugin_definition[$facet],
'href' => $plugin_definition['path'] . '/' . $this
->getPluginId() . '/' . $facet . ':' . $display_plugin_definition[$facet],
);
}
protected function facetCompare($facet, $display_plugin_definition) {
list($facet_type, $option) = explode(':', $facet);
return $option == $display_plugin_definition[$facet_type];
}
protected function allPluginsUrl($display_plugin_id, $display_plugin_definition) {
$plugin_definition = $this
->getPluginDefinition();
return $plugin_definition['path'] . '/' . $this
->getPluginId() . '/add';
}
}