本文整理汇总了PHP中Drupal\views\Views::pluginManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Views::pluginManager方法的具体用法?PHP Views::pluginManager怎么用?PHP Views::pluginManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\views\Views
的用法示例。
在下文中一共展示了Views::pluginManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE)
{
$required = FALSE;
$this->queryParseSearchExpression($this->argument);
if (!isset($this->searchQuery)) {
$required = TRUE;
} else {
$words = $this->searchQuery->words();
if (empty($words)) {
$required = TRUE;
}
}
if ($required) {
if ($this->operator == 'required') {
$this->query->addWhere(0, 'FALSE');
}
} else {
$search_index = $this->ensureMyTable();
$search_condition = db_and();
// Create a new join to relate the 'search_total' table to our current 'search_index' table.
$definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word');
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$search_total = $this->query->addRelationship('search_total', $join, $search_index);
// Add the search score field to the query.
$this->search_score = $this->query->addField('', "{$search_index}.score * {$search_total}.count", 'score', array('function' => 'sum'));
// Add the conditions set up by the search query to the views query.
$search_condition->condition("{$search_index}.type", $this->searchType);
$search_dataset = $this->query->addTable('node_search_dataset');
$conditions = $this->searchQuery->conditions();
$condition_conditions =& $conditions->conditions();
foreach ($condition_conditions as $key => &$condition) {
// Make sure we just look at real conditions.
if (is_numeric($key)) {
// Replace the conditions with the table alias of views.
$this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition);
}
}
$search_conditions =& $search_condition->conditions();
$search_conditions = array_merge($search_conditions, $condition_conditions);
// Add the keyword conditions, as is done in
// SearchQuery::prepareAndNormalize(), but simplified because we are
// only concerned with relevance ranking so we do not need to normalize.
$or = db_or();
foreach ($words as $word) {
$or->condition("{$search_index}.word", $word);
}
$search_condition->condition($or);
// Add the GROUP BY and HAVING expressions to the query.
$this->query->addWhere(0, $search_condition);
$this->query->addGroupBy("{$search_index}.sid");
$matches = $this->searchQuery->matches();
$placeholder = $this->placeholder();
$this->query->addHavingExpression(0, "COUNT(*) >= {$placeholder}", array($placeholder => $matches));
}
// Set to NULL to prevent PDO exception when views object is cached
// and to clear out memory.
$this->searchQuery = NULL;
}
示例2: testDisplayPluginsAlter
/**
* Tests views_ui_views_plugins_display_alter is altering plugin definitions.
*/
public function testDisplayPluginsAlter()
{
$definitions = Views::pluginManager('display')->getDefinitions();
$expected = array('route_name' => 'entity.view.edit_form', 'route_parameters_names' => array('view' => 'id'));
// Test the expected views_ui array exists on each definition.
foreach ($definitions as $definition) {
$this->assertIdentical($definition['contextual links']['entity.view.edit_form'], $expected, 'Expected views_ui array found in plugin definition.');
}
}
示例3: query
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE)
{
$required = FALSE;
$this->queryParseSearchExpression($this->argument);
if (!isset($this->searchQuery)) {
$required = TRUE;
} else {
$words = $this->searchQuery->words();
if (empty($words)) {
$required = TRUE;
}
}
if ($required) {
if ($this->operator == 'required') {
$this->query->addWhere(0, 'FALSE');
}
} else {
$search_index = $this->ensureMyTable();
$search_condition = db_and();
// Create a new join to relate the 'search_total' table to our current 'search_index' table.
$definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word');
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$search_total = $this->query->addRelationship('search_total', $join, $search_index);
$this->search_score = $this->query->addField('', "SUM({$search_index}.score * {$search_total}.count)", 'score', array('aggregate' => TRUE));
$search_condition->condition("{$search_index}.type", $this->searchType);
if (!$this->searchQuery->simple()) {
$search_dataset = $this->query->addTable('search_dataset');
$conditions = $this->searchQuery->conditions();
$condition_conditions =& $conditions->conditions();
foreach ($condition_conditions as $key => &$condition) {
// Make sure we just look at real conditions.
if (is_numeric($key)) {
// Replace the conditions with the table alias of views.
$this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition);
}
}
$search_conditions =& $search_condition->conditions();
$search_conditions = array_merge($search_conditions, $condition_conditions);
} else {
// Stores each condition, so and/or on the filter level will still work.
$or = db_or();
foreach ($words as $word) {
$or->condition("{$search_index}.word", $word);
}
$search_condition->condition($or);
}
$this->query->addWhere(0, $search_condition);
$this->query->addGroupBy("{$search_index}.sid");
$matches = $this->searchQuery->matches();
$placeholder = $this->placeholder();
$this->query->addHavingExpression(0, "COUNT(*) >= {$placeholder}", array($placeholder => $matches));
}
// Set to NULL to prevent PDO exception when views object is cached
// and to clear out memory.
$this->searchQuery = NULL;
}
示例4: query
public function query()
{
$this->ensureMyTable();
$max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH;
for ($i = 1; $i <= $max_depth; ++$i) {
if ($this->options['sort_within_level']) {
$definition = array('table' => 'menu_links', 'field' => 'mlid', 'left_table' => $this->tableAlias, 'left_field' => $this->field . $i);
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$menu_links = $this->query->addTable('menu_links', NULL, $join);
$this->query->addOrderBy($menu_links, 'weight', $this->options['order']);
$this->query->addOrderBy($menu_links, 'link_title', $this->options['order']);
}
// We need this even when also sorting by weight and title, to make sure
// that children of two parents with the same weight and title are
// correctly separated.
$this->query->addOrderBy($this->tableAlias, $this->field . $i, $this->options['order']);
}
}
示例5: query
/**
* {@inheritdoc}
*/
public function query()
{
$this->ensureMyTable();
// Therefore construct the join.
// Add the join for the tmgmt_job_item table.
$configuration = array('table' => 'tmgmt_job_item', 'field' => 'tjid', 'left_table' => $this->tableAlias, 'left_field' => 'tjid', 'operator' => '=');
if (!empty($this->options['state'])) {
$configuration['extra'] = [['field' => 'state', 'value' => $this->options['state']]];
}
/** @var \Drupal\views\Plugin\views\join\Standard $join */
$join = Views::pluginManager('join')->createInstance('standard', $configuration);
// Add the join to the tmgmt_job_item table.
$this->tableAlias = $this->query->addTable('tmgmt_job_item', $this->relationship, $join);
// And finally add the count of the job items field.
$params = array('function' => 'count');
$this->field_alias = $this->query->addField($this->tableAlias, 'tjiid', NULL, $params);
$this->addAdditionalFields();
}
示例6: render
/**
* Renders this view for a certain display.
*
* Note: You should better use just the preview function if you want to
* render a view.
*
* @param string $display_id
* The machine name of the display, which should be rendered.
*
* @return array|null
* A renderable array containing the view output or NULL if the build
* process failed.
*/
public function render($display_id = NULL)
{
$this->execute($display_id);
// Check to see if the build failed.
if (!empty($this->build_info['fail'])) {
return;
}
if (!empty($this->build_info['denied'])) {
return;
}
$exposed_form = $this->display_handler->getPlugin('exposed_form');
$exposed_form->preRender($this->result);
$module_handler = \Drupal::moduleHandler();
// @TODO In the longrun, it would be great to execute a view without
// the theme system at all. See https://www.drupal.org/node/2322623.
$active_theme = \Drupal::theme()->getActiveTheme();
$themes = array_keys($active_theme->getBaseThemes());
$themes[] = $active_theme->getName();
// Check for already-cached output.
/** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
if (!empty($this->live_preview)) {
$cache = Views::pluginManager('cache')->createInstance('none');
} else {
$cache = $this->display_handler->getPlugin('cache');
}
// Run preRender for the pager as it might change the result.
if (!empty($this->pager)) {
$this->pager->preRender($this->result);
}
// Initialize the style plugin.
$this->initStyle();
if (!isset($this->response)) {
// Set the response so other parts can alter it.
$this->response = new Response('', 200);
}
// Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering.
if ($this->style_plugin->usesFields()) {
foreach ($this->field as $id => $handler) {
if (!empty($this->field[$id])) {
$this->field[$id]->preRender($this->result);
}
}
}
$this->style_plugin->preRender($this->result);
// Let each area handler have access to the result set.
$areas = array('header', 'footer');
// Only call preRender() on the empty handlers if the result is empty.
if (empty($this->result)) {
$areas[] = 'empty';
}
foreach ($areas as $area) {
foreach ($this->{$area} as $handler) {
$handler->preRender($this->result);
}
}
// Let modules modify the view just prior to rendering it.
$module_handler->invokeAll('views_pre_render', array($this));
// Let the themes play too, because pre render is a very themey thing.
foreach ($themes as $theme_name) {
$function = $theme_name . '_views_pre_render';
if (function_exists($function)) {
$function($this);
}
}
$this->display_handler->output = $this->display_handler->render();
$exposed_form->postRender($this->display_handler->output);
$cache->postRender($this->display_handler->output);
// Let modules modify the view output after it is rendered.
$module_handler->invokeAll('views_post_render', array($this, &$this->display_handler->output, $cache));
// Let the themes play too, because post render is a very themey thing.
foreach ($themes as $theme_name) {
$function = $theme_name . '_views_post_render';
if (function_exists($function)) {
$function($this, $this->display_handler->output, $cache);
}
}
return $this->display_handler->output;
}
示例7: getTableJoin
/**
* {@inheritdoc}
*/
public static function getTableJoin($table, $base_table)
{
$data = Views::viewsData()->get($table);
if (isset($data['table']['join'][$base_table])) {
$join_info = $data['table']['join'][$base_table];
if (!empty($join_info['join_id'])) {
$id = $join_info['join_id'];
} else {
$id = 'standard';
}
$configuration = $join_info;
// Fill in some easy defaults.
if (empty($configuration['table'])) {
$configuration['table'] = $table;
}
// If this is empty, it's a direct link.
if (empty($configuration['left_table'])) {
$configuration['left_table'] = $base_table;
}
if (isset($join_info['arguments'])) {
foreach ($join_info['arguments'] as $key => $argument) {
$configuration[$key] = $argument;
}
}
$join = Views::pluginManager('join')->createInstance($id, $configuration);
return $join;
}
}
示例8: defaultDisplayFiltersUser
/**
* Retrieves filter information based on user input for the default display.
*
* @param array $form
* The full wizard form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the wizard form.
*
* @return array
* An array of filter arrays keyed by ID. A sort array contains the options
* accepted by a filter handler.
*/
protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state)
{
$filters = array();
if (($type = $form_state->getValue(array('show', 'type'))) && $type != 'all') {
$bundle_key = $this->entityType->getKey('bundle');
// Figure out the table where $bundle_key lives. It may not be the same as
// the base table for the view; the taxonomy vocabulary machine_name, for
// example, is stored in taxonomy_vocabulary, not taxonomy_term_data.
module_load_include('inc', 'views_ui', 'admin');
$fields = Views::viewsDataHelper()->fetchFields($this->base_table, 'filter');
if (isset($fields[$this->base_table . '.' . $bundle_key])) {
$table = $this->base_table;
} else {
foreach ($fields as $field_name => $value) {
if ($pos = strpos($field_name, '.' . $bundle_key)) {
$table = substr($field_name, 0, $pos);
break;
}
}
}
$table_data = Views::viewsData()->get($table);
// If the 'in' operator is being used, map the values to an array.
$handler = $table_data[$bundle_key]['filter']['id'];
$handler_definition = Views::pluginManager('filter')->getDefinition($handler);
if ($handler == 'in_operator' || is_subclass_of($handler_definition['class'], 'Drupal\\views\\Plugin\\views\\filter\\InOperator')) {
$value = array($type => $type);
} else {
$value = $type;
}
$filters[$bundle_key] = array('id' => $bundle_key, 'table' => $table, 'field' => $bundle_key, 'value' => $value);
}
return $filters;
}
示例9: query
/**
* {@inheritdoc}
*/
public function query()
{
// Figure out what base table this relationship brings to the party.
$table_data = Views::viewsData()->get($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this->ensureMyTable();
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->tableAlias;
$def['left_field'] = $this->field;
$def['adjusted'] = TRUE;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
if ($this->options['subquery_regenerate']) {
// For testing only, regenerate the subquery each time.
$def['left_query'] = $this->leftQuery($this->options);
} else {
// Get the stored subquery SQL string.
$cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
$cache = \Drupal::cache('data')->get($cid);
if (isset($cache->data)) {
$def['left_query'] = $cache->data;
} else {
$def['left_query'] = $this->leftQuery($this->options);
\Drupal::cache('data')->set($cid, $def['left_query']);
}
}
if (!empty($def['join_id'])) {
$id = $def['join_id'];
} else {
$id = 'subquery';
}
$join = Views::pluginManager('join')->createInstance($id, $def);
// use a short alias for this:
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query->addRelationship($alias, $join, $this->definition['base'], $this->relationship);
}
示例10: submitOptionsForm
/**
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
public function submitOptionsForm(&$form, &$form_state)
{
// Not sure I like this being here, but it seems (?) like a logical place.
$cache_plugin = $this->getPlugin('cache');
if ($cache_plugin) {
$cache_plugin->cacheFlush();
}
$section = $form_state['section'];
switch ($section) {
case 'display_id':
if (isset($form_state['values']['display_id'])) {
$this->display['new_id'] = $form_state['values']['display_id'];
}
break;
case 'display_title':
$this->display['display_title'] = $form_state['values']['display_title'];
$this->setOption('display_description', $form_state['values']['display_description']);
break;
case 'query':
$plugin = $this->getPlugin('query');
if ($plugin) {
$plugin->submitOptionsForm($form['query']['options'], $form_state);
$this->setOption('query', $form_state['values'][$section]);
}
break;
case 'link_display':
$this->setOption('link_url', $form_state['values']['link_url']);
case 'title':
case 'css_class':
case 'display_comment':
case 'distinct':
case 'group_by':
$this->setOption($section, $form_state['values'][$section]);
break;
case 'field_langcode':
$this->setOption('field_langcode', $form_state['values']['field_langcode']);
$this->setOption('field_langcode_add_to_query', $form_state['values']['field_langcode_add_to_query']);
break;
case 'use_ajax':
case 'hide_attachment_summary':
case 'show_admin_links':
case 'exposed_block':
$this->setOption($section, (bool) $form_state['values'][$section]);
break;
case 'use_more':
$this->setOption($section, intval($form_state['values'][$section]));
$this->setOption('use_more_always', intval($form_state['values']['use_more_always']));
$this->setOption('use_more_text', $form_state['values']['use_more_text']);
break;
case 'access':
case 'cache':
case 'exposed_form':
case 'pager':
case 'row':
case 'style':
$plugin_type = $section;
$plugin_options = $this->getOption($plugin_type);
if ($plugin_options['type'] != $form_state['values'][$plugin_type]['type']) {
$plugin = Views::pluginManager($plugin_type)->createInstance($form_state['values'][$plugin_type]['type']);
if ($plugin) {
$plugin->init($this->view, $this, $plugin_options['options']);
$plugin_options = array('type' => $form_state['values'][$plugin_type]['type'], 'options' => $plugin->options, 'provider' => $plugin->definition['provider']);
$this->setOption($plugin_type, $plugin_options);
if ($plugin->usesOptions()) {
$form_state['view']->addFormToStack('display', $this->display['id'], $plugin_type . '_options');
}
}
}
break;
case 'access_options':
case 'cache_options':
case 'exposed_form_options':
case 'pager_options':
case 'row_options':
case 'style_options':
// Submit plugin options. Every section with "_options" in it, belongs to
// a plugin type, like "style_options".
$plugin_type = str_replace('_options', '', $form_state['section']);
if ($plugin = $this->getPlugin($plugin_type)) {
$plugin_options = $this->getOption($plugin_type);
$plugin->submitOptionsForm($form[$plugin_type . '_options'], $form_state);
$plugin_options['options'] = $form_state['values'][$section];
$this->setOption($plugin_type, $plugin_options);
}
break;
}
foreach ($this->extender as $extender) {
$extender->submitOptionsForm($form, $form_state);
}
}
示例11: query
/**
* {@inheritdoc}
*/
public function query()
{
// Since attachment views don't validate the exposed input, parse the search
// expression if required.
if (!$this->parsed) {
$this->queryParseSearchExpression($this->value);
}
$required = FALSE;
if (!isset($this->searchQuery)) {
$required = TRUE;
} else {
$words = $this->searchQuery->words();
if (empty($words)) {
$required = TRUE;
}
}
if ($required) {
if ($this->operator == 'required') {
$this->query->addWhere($this->options['group'], 'FALSE');
}
} else {
$search_index = $this->ensureMyTable();
$search_condition = db_and();
// Create a new join to relate the 'search_total' table to our current
// 'search_index' table.
$definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word');
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$search_total = $this->query->addRelationship('search_total', $join, $search_index);
$this->search_score = $this->query->addField('', "{$search_index}.score * {$search_total}.count", 'score', array('function' => 'sum'));
$search_condition->condition("{$search_index}.type", $this->searchType);
$search_dataset = $this->query->addTable('node_search_dataset');
$conditions = $this->searchQuery->conditions();
$condition_conditions =& $conditions->conditions();
foreach ($condition_conditions as $key => &$condition) {
// Make sure we just look at real conditions.
if (is_numeric($key)) {
// Replace the conditions with the table alias of views.
$this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition);
}
}
$search_conditions =& $search_condition->conditions();
$search_conditions = array_merge($search_conditions, $condition_conditions);
$this->query->addWhere($this->options['group'], $search_condition);
$this->query->addGroupBy("{$search_index}.sid");
$matches = $this->searchQuery->matches();
$placeholder = $this->placeholder();
$this->query->addHavingExpression($this->options['group'], "COUNT(*) >= {$placeholder}", array($placeholder => $matches));
}
// Set to NULL to prevent PDO exception when views object is cached.
$this->searchQuery = NULL;
}
示例12: getRoute
/**
* Generates a route entry for a given view and display.
*
* @param string $view_id
* The ID of the view.
* @param string $display_id
* The current display ID.
*
* @return \Symfony\Component\Routing\Route
* The route for the view.
*/
protected function getRoute($view_id, $display_id)
{
$defaults = array('_controller' => 'Drupal\\views\\Routing\\ViewPageController::handle', 'view_id' => $view_id, 'display_id' => $display_id, '_view_display_show_admin_links' => $this->getOption('show_admin_links'));
// @todo How do we apply argument validation?
$bits = explode('/', $this->getOption('path'));
// @todo Figure out validation/argument loading.
// Replace % with %views_arg for menu autoloading and add to the
// page arguments so the argument actually comes through.
$arg_counter = 0;
$argument_ids = array_keys((array) $this->getOption('arguments'));
$total_arguments = count($argument_ids);
$argument_map = array();
// Replace arguments in the views UI (defined via %) with parameters in
// routes (defined via {}). As a name for the parameter use arg_$key, so
// it can be pulled in the views controller from the request.
foreach ($bits as $pos => $bit) {
if ($bit == '%') {
// Generate the name of the parameter using the key of the argument
// handler.
$arg_id = 'arg_' . $arg_counter++;
$bits[$pos] = '{' . $arg_id . '}';
$argument_map[$arg_id] = $arg_id;
} elseif (strpos($bit, '%') === 0) {
// Use the name defined in the path.
$parameter_name = substr($bit, 1);
$arg_id = 'arg_' . $arg_counter++;
$argument_map[$arg_id] = $parameter_name;
$bits[$pos] = '{' . $parameter_name . '}';
}
}
// Add missing arguments not defined in the path, but added as handler.
while ($total_arguments - $arg_counter > 0) {
$arg_id = 'arg_' . $arg_counter++;
$bit = '{' . $arg_id . '}';
// In contrast to the previous loop add the defaults here, as % was not
// specified, which means the argument is optional.
$defaults[$arg_id] = NULL;
$argument_map[$arg_id] = $arg_id;
$bits[] = $bit;
}
// If this is to be a default tab, create the route for the parent path.
if ($this->isDefaultTabPath()) {
$bit = array_pop($bits);
if (empty($bits)) {
$bits[] = $bit;
}
}
$route_path = '/' . implode('/', $bits);
$route = new Route($route_path, $defaults);
// Add access check parameters to the route.
$access_plugin = $this->getPlugin('access');
if (!isset($access_plugin)) {
// @todo Do we want to support a default plugin in getPlugin itself?
$access_plugin = Views::pluginManager('access')->createInstance('none');
}
$access_plugin->alterRouteDefinition($route);
// Set the argument map, in order to support named parameters.
$route->setOption('_view_argument_map', $argument_map);
$route->setOption('_view_display_plugin_id', $this->getPluginId());
$route->setOption('_view_display_plugin_class', get_called_class());
$route->setOption('_view_display_show_admin_links', $this->getOption('show_admin_links'));
// Store whether the view will return a response.
$route->setOption('returns_response', !empty($this->getPluginDefinition()['returns_response']));
return $route;
}
示例13: query
/**
* {@inheritdoc}
*/
public function query()
{
// Figure out what base table this relationship brings to the party.
$table_data = Views::viewsData()->get($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this->ensureMyTable();
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->tableAlias;
$def['left_field'] = $this->realField;
$def['adjusted'] = TRUE;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
if (!empty($this->definition['extra'])) {
$def['extra'] = $this->definition['extra'];
}
if (!empty($def['join_id'])) {
$id = $def['join_id'];
} else {
$id = 'standard';
}
$join = Views::pluginManager('join')->createInstance($id, $def);
// use a short alias for this:
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query->addRelationship($alias, $join, $this->definition['base'], $this->relationship);
// Add access tags if the base table provide it.
if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
$access_tag = $table_data['table']['base']['access query tag'];
$this->query->addTag($access_tag);
}
}
示例14: addHandler
/**
* Adds an instance of a handler to the view.
*
* Items may be fields, filters, sort criteria, or arguments.
*
* @param string $display_id
* The machine name of the display.
* @param string $type
* The type of handler being added.
* @param string $table
* The name of the table this handler is from.
* @param string $field
* The name of the field this handler is from.
* @param array $options
* (optional) Extra options for this instance. Defaults to an empty array.
* @param string $id
* (optional) A unique ID for this handler instance. Defaults to NULL, in
* which case one will be generated.
*
* @return string
* The unique ID for this handler instance.
*/
public function addHandler($display_id, $type, $table, $field, $options = array(), $id = NULL)
{
$types = $this::getHandlerTypes();
$this->setDisplay($display_id);
$fields = $this->displayHandlers->get($display_id)->getOption($types[$type]['plural']);
if (empty($id)) {
$id = $this->generateHandlerId($field, $fields);
}
// If the desired type is not found, use the original value directly.
$handler_type = !empty($types[$type]['type']) ? $types[$type]['type'] : $type;
$fields[$id] = array('id' => $id, 'table' => $table, 'field' => $field) + $options;
// Load the plugin ID if available.
$data = Views::viewsData()->get($table);
if (isset($data[$field][$handler_type]['id'])) {
$fields[$id]['plugin_id'] = $data[$field][$handler_type]['id'];
if ($definition = Views::pluginManager($handler_type)->getDefinition($fields[$id]['plugin_id'], FALSE)) {
$fields[$id]['provider'] = isset($definition['provider']) ? $definition['provider'] : 'views';
}
}
$this->displayHandlers->get($display_id)->setOption($types[$type]['plural'], $fields);
return $id;
}
示例15: addDisplay
/**
* Adds a new display handler to the view, automatically creating an ID.
*
* @param string $plugin_id
* (optional) The plugin type from the Views plugin annotation. Defaults to
* 'page'.
* @param string $title
* (optional) The title of the display. Defaults to NULL.
* @param string $id
* (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults
* to NULL.
*
* @return string|false
* The key to the display in $view->display, or FALSE if no plugin ID was
* provided.
*/
public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL)
{
if (empty($plugin_id)) {
return FALSE;
}
$plugin = Views::pluginManager('display')->getDefinition($plugin_id);
if (empty($plugin)) {
$plugin['title'] = t('Broken');
}
if (empty($id)) {
$id = $this->generateDisplayId($plugin_id);
// Generate a unique human-readable name by inspecting the counter at the
// end of the previous display ID, e.g., 'page_1'.
if ($id !== 'default') {
preg_match("/[0-9]+/", $id, $count);
$count = $count[0];
} else {
$count = '';
}
if (empty($title)) {
// If there is no title provided, use the plugin title, and if there are
// multiple displays, append the count.
$title = $plugin['title'];
if ($count > 1) {
$title .= ' ' . $count;
}
}
}
$display_options = array('display_plugin' => $plugin_id, 'id' => $id, 'display_title' => (string) $title, 'position' => $id === 'default' ? 0 : count($this->display), 'provider' => $plugin['provider'], 'display_options' => array());
// Add the display options to the view.
$this->display[$id] = $display_options;
return $id;
}