本文整理汇总了PHP中Drupal\views\Views::handlerManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Views::handlerManager方法的具体用法?PHP Views::handlerManager怎么用?PHP Views::handlerManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\views\Views
的用法示例。
在下文中一共展示了Views::handlerManager方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildOptionsForm
/**
* Provide a form for setting options.
*/
public function buildOptionsForm(&$form, &$form_state)
{
parent::buildOptionsForm($form, $form_state);
if (isset($this->base_table)) {
$executable = $form_state['view']->getExecutable();
// A whole bunch of code to figure out what relationships are valid for
// this item.
$relationships = $executable->display_handler->getOption('relationships');
$relationship_options = array();
foreach ($relationships as $relationship) {
$relationship_handler = Views::handlerManager('relationship')->getHandler($relationship);
// If this relationship is valid for this type, add it to the list.
$data = Views::viewsData()->get($relationship['table']);
$base = $data[$relationship['field']]['relationship']['base'];
if ($base == $this->base_table) {
$relationship_handler->init($executable, $relationship);
$relationship_options[$relationship['id']] = $relationship_handler->adminLabel();
}
}
if (!empty($relationship_options)) {
$relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
$rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
if (empty($relationship_options[$rel])) {
// Pick the first relationship.
$rel = key($relationship_options);
}
$form['relationship'] = array('#type' => 'select', '#title' => t('Relationship'), '#options' => $relationship_options, '#default_value' => $rel);
} else {
$form['relationship'] = array('#type' => 'value', '#value' => 'none');
}
}
}
示例2: init
/**
* Overrides \Drupal\views\Plugin\views\HandlerBase::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
{
parent::init($view, $display, $options);
// Initialize the original handler.
$this->handler = Views::handlerManager('sort')->getHandler($options);
$this->handler->init($view, $display, $options);
}
示例3: preRender
public function preRender($values)
{
if (!$this->exposedFilterApplied()) {
$options = array('id' => 'area', 'table' => 'views', 'field' => 'area', 'label' => '', 'relationship' => 'none', 'group_type' => 'group', 'content' => $this->options['text_input_required'], 'format' => $this->options['text_input_required_format']);
$handler = Views::handlerManager('area')->getHandler($options);
$handler->init($this->view, $this->displayHandler, $options);
$this->displayHandler->handlers['empty'] = array('area' => $handler);
$this->displayHandler->setOption('empty', array('text' => $options));
}
}
示例4: init
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
{
// Prepare our fallback handler.
$fallback_handler_id = !empty($this->definition['fallback_handler']) ? $this->definition['fallback_handler'] : 'search_api';
$this->fallbackHandler = Views::handlerManager('field')->getHandler($options, $fallback_handler_id);
$options += array('fallback_options' => array());
$fallback_options = $options['fallback_options'] + $options;
$this->fallbackHandler->init($view, $display, $fallback_options);
parent::init($view, $display, $options);
}
示例5: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
$item =& $form_state['handler']->options;
$type = $form_state['type'];
$handler = Views::handlerManager($type)->getHandler($item);
$executable = $form_state['view']->getExecutable();
$handler->init($executable, $executable->display_handler, $item);
$handler->submitGroupByForm($form, $form_state);
// Store the item back on the view
$executable->setHandler($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
// Write to cache
$form_state['view']->cacheSet();
}
示例6: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$view = $form_state->get('view');
$item =& $form_state->get('handler')->options;
$type = $form_state->get('type');
$handler = Views::handlerManager($type)->getHandler($item);
$executable = $view->getExecutable();
$handler->init($executable, $executable->display_handler, $item);
$handler->submitGroupByForm($form, $form_state);
// Store the item back on the view
$executable->setHandler($form_state->get('display_id'), $form_state->get('type'), $form_state->get('id'), $item);
// Write to cache
$view->cacheSet();
}
示例7: preRender
public function preRender($values)
{
// Display the "text on demand" if needed. This is a site builder-defined
// text to display instead of results until the user selects and applies
// an exposed filter.
if (!$this->exposedFilterApplied()) {
$options = array('id' => 'area', 'table' => 'views', 'field' => 'area', 'label' => '', 'relationship' => 'none', 'group_type' => 'group', 'empty' => TRUE, 'content' => ['value' => $this->options['text_input_required'], 'format' => $this->options['text_input_required_format']]);
$handler = Views::handlerManager('area')->getHandler($options);
$handler->init($this->view, $this->displayHandler, $options);
$this->displayHandler->handlers['empty'] = array('area' => $handler);
// Override the existing empty result message (if applicable).
$this->displayHandler->setOption('empty', array('text' => $options));
}
}
示例8: array
/**
* {@inheritdoc}
*/
public function &getHandlers($type)
{
if (!isset($this->handlers[$type])) {
$this->handlers[$type] = array();
$types = ViewExecutable::getHandlerTypes();
$plural = $types[$type]['plural'];
// Cast to an array so that if the display does not have any handlers of
// this type there is no PHP error.
foreach ((array) $this->getOption($plural) as $id => $info) {
// If this is during form submission and there are temporary options
// which can only appear if the view is in the edit cache, use those
// options instead. This is used for AJAX multi-step stuff.
if ($this->view->getRequest()->request->get('form_id') && isset($this->view->temporary_options[$type][$id])) {
$info = $this->view->temporary_options[$type][$id];
}
if ($info['id'] != $id) {
$info['id'] = $id;
}
// If aggregation is on, the group type might override the actual
// handler that is in use. This piece of code checks that and,
// if necessary, sets the override handler.
$override = NULL;
if ($this->useGroupBy() && !empty($info['group_type'])) {
if (empty($this->view->query)) {
$this->view->initQuery();
}
$aggregate = $this->view->query->getAggregationInfo();
if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
$override = $aggregate[$info['group_type']]['handler'][$type];
}
}
if (!empty($types[$type]['type'])) {
$handler_type = $types[$type]['type'];
} else {
$handler_type = $type;
}
if ($handler = Views::handlerManager($handler_type)->getHandler($info, $override)) {
// Special override for area types so they know where they come from.
if ($handler instanceof AreaPluginBase) {
$handler->areaType = $type;
}
$handler->init($this->view, $this, $info);
$this->handlers[$type][$id] =& $handler;
}
// Prevent reference problems.
unset($handler);
}
}
return $this->handlers[$type];
}
示例9: submitItemAdd
/**
* Submit handler for adding new item(s) to a view.
*/
public function submitItemAdd($form, FormStateInterface $form_state)
{
$type = $form_state->get('type');
$types = ViewExecutable::getHandlerTypes();
$section = $types[$type]['plural'];
$display_id = $form_state->get('display_id');
// Handle the override select.
list($was_defaulted, $is_defaulted) = $this->getOverrideValues($form, $form_state);
if ($was_defaulted && !$is_defaulted) {
// We were using the default display's values, but we're now overriding
// the default display and saving values specific to this display.
$display =& $this->getExecutable()->displayHandlers->get($display_id);
// setOverride toggles the override of this section.
$display->setOverride($section);
} elseif (!$was_defaulted && $is_defaulted) {
// We used to have an override for this display, but the user now wants
// to go back to the default display.
// Overwrite the default display with the current form values, and make
// the current display use the new default values.
$display =& $this->getExecutable()->displayHandlers->get($display_id);
// optionsOverride toggles the override of this section.
$display->setOverride($section);
}
if (!$form_state->isValueEmpty('name') && is_array($form_state->getValue('name'))) {
// Loop through each of the items that were checked and add them to the view.
foreach (array_keys(array_filter($form_state->getValue('name'))) as $field) {
list($table, $field) = explode('.', $field, 2);
if ($cut = strpos($field, '$')) {
$field = substr($field, 0, $cut);
}
$id = $this->getExecutable()->addHandler($display_id, $type, $table, $field);
// check to see if we have group by settings
$key = $type;
// Footer,header and empty text have a different internal handler type(area).
if (isset($types[$type]['type'])) {
$key = $types[$type]['type'];
}
$item = array('table' => $table, 'field' => $field);
$handler = Views::handlerManager($key)->getHandler($item);
if ($this->getExecutable()->displayHandlers->get('default')->useGroupBy() && $handler->usesGroupBy()) {
$this->addFormToStack('handler-group', $display_id, $type, $id);
}
// check to see if this type has settings, if so add the settings form first
if ($handler && $handler->hasExtraOptions()) {
$this->addFormToStack('handler-extra', $display_id, $type, $id);
}
// Then add the form to the stack
$this->addFormToStack('handler', $display_id, $type, $id);
}
}
if (isset($this->form_cache)) {
unset($this->form_cache);
}
// Store in cache
$this->cacheSet();
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
// Run it through the handler's submit function.
$form_state['handler']->submitOptionsForm($form['options'], $form_state);
$item = $form_state['handler']->options;
$types = ViewExecutable::getHandlerTypes();
// For footer/header $handler_type is area but $type is footer/header.
// For all other handle types it's the same.
$handler_type = $type = $form_state['type'];
if (!empty($types[$type]['type'])) {
$handler_type = $types[$type]['type'];
}
$override = NULL;
$executable = $form_state['view']->getExecutable();
if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) {
if (empty($executable->query)) {
$executable->initQuery();
}
$aggregate = $executable->query->getAggregationInfo();
if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
$override = $aggregate[$item['group_type']]['handler'][$type];
}
}
// Create a new handler and unpack the options from the form onto it. We
// can use that for storage.
$handler = Views::handlerManager($handler_type)->getHandler($item, $override);
$handler->init($executable, $executable->display_handler, $item);
// Add the incoming options to existing options because items using
// the extra form may not have everything in the form here.
$options = $form_state['values']['options'] + $form_state['handler']->options;
// This unpacks only options that are in the definition, ensuring random
// extra stuff on the form is not sent through.
$handler->unpackOptions($handler->options, $options, NULL, FALSE);
// Add any dependencies as the handler is saved. Put it here so
// it does not need to be declared in defineOptions().
if ($dependencies = $handler->getDependencies()) {
$handler->options['dependencies'] = $dependencies;
}
// Add the module providing the handler as a dependency as well.
$handler->options['dependencies']['module'][] = $handler->definition['provider'];
// Store the item back on the view
$executable->setHandler($form_state['display_id'], $form_state['type'], $form_state['id'], $handler->options);
// Ensure any temporary options are removed.
if (isset($form_state['view']->temporary_options[$type][$form_state['id']])) {
unset($form_state['view']->temporary_options[$type][$form_state['id']]);
}
// Write to cache
$form_state['view']->cacheSet();
}
示例11: submitTemporaryForm
/**
* A submit handler that is used for storing temporary items when using
* multi-step changes, such as ajax requests.
*/
public function submitTemporaryForm($form, FormStateInterface $form_state)
{
// Run it through the handler's submit function.
$this->submitOptionsForm($form['options'], $form_state);
$item = $this->options;
$types = ViewExecutable::getHandlerTypes();
// For footer/header $handler_type is area but $type is footer/header.
// For all other handle types it's the same.
$handler_type = $type = $form_state->get('type');
if (!empty($types[$type]['type'])) {
$handler_type = $types[$type]['type'];
}
$override = NULL;
$view = $form_state->get('view');
$executable = $view->getExecutable();
if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) {
if (empty($executable->query)) {
$executable->initQuery();
}
$aggregate = $executable->query->getAggregationInfo();
if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
$override = $aggregate[$item['group_type']]['handler'][$type];
}
}
// Create a new handler and unpack the options from the form onto it. We
// can use that for storage.
$handler = Views::handlerManager($handler_type)->getHandler($item, $override);
$handler->init($executable, $executable->display_handler, $item);
// Add the incoming options to existing options because items using
// the extra form may not have everything in the form here.
$options = $form_state->getValue('options') + $this->options;
// This unpacks only options that are in the definition, ensuring random
// extra stuff on the form is not sent through.
$handler->unpackOptions($handler->options, $options, NULL, FALSE);
// Store the item back on the view.
$executable = $view->getExecutable();
$executable->temporary_options[$type][$form_state->get('id')] = $handler->options;
// @todo Decide if \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm() is
// perhaps the better place to fix the issue.
// \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm() drops the current
// form from the stack, even if it's an #ajax. So add the item back to the top
// of the stack.
$view->addFormToStack($form_state->get('form_key'), $form_state->get('display_id'), $type, $item['id'], TRUE);
$form_state->get('rerender', TRUE);
$form_state->setRebuild();
// Write to cache
$view->cacheSet();
}
示例12: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$view = $form_state->get('view');
$display_id = $form_state->get('display_id');
$id = $form_state->get('id');
$handler = $form_state->get('handler');
// Run it through the handler's submit function.
$handler->submitOptionsForm($form['options'], $form_state);
$item = $handler->options;
$types = ViewExecutable::getHandlerTypes();
// For footer/header $handler_type is area but $type is footer/header.
// For all other handle types it's the same.
$handler_type = $type = $form_state->get('type');
if (!empty($types[$type]['type'])) {
$handler_type = $types[$type]['type'];
}
$override = NULL;
$executable = $view->getExecutable();
if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) {
if (empty($executable->query)) {
$executable->initQuery();
}
$aggregate = $executable->query->getAggregationInfo();
if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
$override = $aggregate[$item['group_type']]['handler'][$type];
}
}
// Create a new handler and unpack the options from the form onto it. We
// can use that for storage.
$handler = Views::handlerManager($handler_type)->getHandler($item, $override);
$handler->init($executable, $executable->display_handler, $item);
// Add the incoming options to existing options because items using
// the extra form may not have everything in the form here.
$options = $form_state->getValue('options') + $handler->options;
// This unpacks only options that are in the definition, ensuring random
// extra stuff on the form is not sent through.
$handler->unpackOptions($handler->options, $options, NULL, FALSE);
// Store the item back on the view
$executable->setHandler($display_id, $type, $id, $handler->options);
// Ensure any temporary options are removed.
if (isset($view->temporary_options[$type][$id])) {
unset($view->temporary_options[$type][$id]);
}
// Write to cache
$view->cacheSet();
}
示例13: dateViewFields
/**
* Helper for identifying Date API fields for views.
*
* This is a ported version of date_views_fields() in date_views module in
* D7.
*
* @param string $base
* @return array
*/
public static function dateViewFields($base = 'node')
{
// Make sure $base is never empty.
if (empty($base)) {
$base = 'node';
}
$cid = 'date_views_fields_' . $base;
// cache_clear_all($cid, 'cache_views');
// We use fields that provide filter handlers as our universe of possible
// fields of interest.
$all_fields = self::viewsFetchFields($base, 'filter');
// Iterate over all the fields that Views knows about.
$fields = [];
foreach ((array) $all_fields as $alias => $value) {
// Set up some default values.
$granularity = ['year', 'month', 'day', 'hour', 'minute', 'second'];
$tz_handling = 'site';
$related_fields = [];
$timezone_field = '';
$offset_field = '';
$rrule_field = '';
$delta_field = '';
// $sql_type = DATE_UNIX;
$sql_type = DATETIME_DATETIME_STORAGE_FORMAT;
$type = '';
$name = $alias;
$tmp = explode('.', $name);
$field_name = $tmp[1];
$table_name = $tmp[0];
// Unset the date filter to avoid ugly recursion and broken values.
if ($field_name == 'date_filter') {
continue;
}
$fromto = [$name, $name];
// If we don't have a filter handler, we don't need to do anything more.
$filterHandler = Views::handlerManager('filter');
$handler = $filterHandler->getHandler(['table' => $table_name, 'field' => $field_name]);
if ($handler instanceof Broken) {
continue;
}
// $handler = views_get_handler($table_name, $field_name, 'filter');
$pluginDefinition = $handler->getPluginDefinition();
// We don't care about anything but date handlers.
if ($pluginDefinition['class'] != 'Drupal\\views\\Plugin\\views\\filter\\Date' && !is_subclass_of($pluginDefinition['class'], 'Drupal\\views\\Plugin\\views\\filter\\Date')) {
continue;
}
$is_field = FALSE;
// For Field module fields, get the date type.
$custom = [];
if ($field_name || isset($handler->definition['field_name'])) {
// $field = FieldConfig::loadByName($field_name);
// $field = field_info_field($handler->definition['field_name']);
$is_field = TRUE;
// switch ($field['type']) {
switch ($handler->getBaseId()) {
case 'date':
$sql_type = DATETIME_DATETIME_STORAGE_FORMAT;
// $sql_type = DATE_ISO;
break;
case 'datestamp':
break;
case 'datetime':
// $sql_type = DATE_DATETIME;
$sql_type = DATETIME_DATETIME_STORAGE_FORMAT;
break;
default:
// If this is not a date field, nothing more to do.
continue;
}
// $revision = in_array($base, array('node_revision')) ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT;
// @todo find database info
// $db_info = date_api_database_info($field, $revision);
$name = $table_name . "." . $field_name;
$grans = ['year', 'month', 'day', 'hour', 'minute', 'second'];
$granularity = !empty($field['granularity']) ? $field['granularity'] : $grans;
// $fromto = array(
// $table_name . '.' . $db_info['columns'][$table_name]['value'],
// $table_name . '.' . (!empty($field['settings']['todate']) ? $db_info['columns'][$table_name]['value2'] : $db_info['columns'][$table_name]['value']),
// );
// if (isset($field['settings']['tz_handling'])) {
// $tz_handling = $field['settings']['tz_handling'];
// $db_info = date_api_database_info($field, $revision);
// if ($tz_handling == 'date') {
// $offset_field = $table_name . '.' . $db_info['columns'][$table_name]['offset'];
// }
// $related_fields = array(
// $table_name . '.' . $db_info['columns'][$table_name]['value'],
// );
// if (isset($db_info['columns'][$table_name]['value2'])) {
// $related_fields = array_merge($related_fields, array($table_name . '.' . $db_info['columns'][$table_name]['value2']));
// }
//.........这里部分代码省略.........