本文整理汇总了PHP中Drupal\views\ViewExecutable::id方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewExecutable::id方法的具体用法?PHP ViewExecutable::id怎么用?PHP ViewExecutable::id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\views\ViewExecutable
的用法示例。
在下文中一共展示了ViewExecutable::id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hook_views_query_alter
/**
* Alter the query before it is executed.
*
* @param \Drupal\views\ViewExecutable $view
* The view object about to be processed.
* @param QueryPluginBase $query
* The query plugin object for the query.
*
* @see hook_views_query_substitutions()
* @see \Drupal\views\Plugin\views\query\Sql
*/
function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query)
{
// (Example assuming a view with an exposed filter on node title.)
// If the input for the title filter is a positive integer, filter against
// node ID instead of node title.
if ($view->id() == 'my_view' && is_numeric($view->exposed_raw_input['title']) && $view->exposed_raw_input['title'] > 0) {
// Traverse through the 'where' part of the query.
foreach ($query->where as &$condition_group) {
foreach ($condition_group['conditions'] as &$condition) {
// If this is the part of the query filtering on title, chang the
// condition to filter on node ID.
if ($condition['field'] == 'node.title') {
$condition = array('field' => 'node.nid', 'value' => $view->exposed_raw_input['title'], 'operator' => '=');
}
}
}
}
}
示例2: assertViewsCacheTagsFromStaticRenderArray
/**
* Asserts a view's result & render cache items' cache tags.
*
* This method starts with a pre bubbling basic render array.
*
* @param \Drupal\views\ViewExecutable $view
* The view.
* @param string[] $expected_render_array_cache_tags
* The expected render cache tags.
* @param bool $views_caching_is_enabled
* Defines whether views output / render caching is enabled.
*
* @return array
* The render array.
*/
protected function assertViewsCacheTagsFromStaticRenderArray(ViewExecutable $view, array $expected_render_array_cache_tags, $views_caching_is_enabled)
{
$original = $build = DisplayPluginBase::buildBasicRenderable($view->id(), $view->current_display ?: 'default', $view->args);
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
/** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
$render_cache = \Drupal::service('render_cache');
// Ensure the current request is a GET request so that render caching is
// active for direct rendering of views, just like for actual requests.
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
$request_stack = \Drupal::service('request_stack');
$request = new Request();
$request->server->set('REQUEST_TIME', REQUEST_TIME);
$request_stack->push($request);
$renderer->renderRoot($build);
// Render array cache tags.
$this->pass('Checking render array cache tags.');
sort($expected_render_array_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_render_array_cache_tags);
$this->debugCacheTags($build['#cache']['tags'], $expected_render_array_cache_tags);
$this->pass('Checking Views render cache item cache tags.');
$original['#cache'] += ['contexts' => []];
$original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
$render_cache_item = $render_cache->get($original);
if ($views_caching_is_enabled) {
$this->assertTrue(!empty($render_cache_item), 'Render cache item found.');
if ($render_cache_item) {
$this->assertEqual($render_cache_item['#cache']['tags'], $expected_render_array_cache_tags);
$this->debugCacheTags($render_cache_item['#cache']['tags'], $expected_render_array_cache_tags);
}
} else {
$this->assertFalse($render_cache_item, 'Render cache item not found.');
}
return $build;
}
示例3: getViewsURL
/**
* Get the Url object to link to a View display with given arguments.
*
* @param \Drupal\views\ViewExecutable $view
* @param $display_id
* @param array $args
*
* @return \Drupal\Core\Url
*/
static function getViewsURL(ViewExecutable $view, $display_id, $args = [])
{
$route_parameters = static::getViewRouteParameters($args);
$route_name = static::getDisplayRouteName($view->id(), $display_id);
return Url::fromRoute($route_name, $route_parameters);
}