/**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     if ($view_mode == 'mail') {
         // Convert field labels into headings.
         // @todo Improve drupal_html_to_text() to convert DIVs correctly.
         foreach (Element::children($build) as $key) {
             if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
                 $build[$key] += array('#prefix' => '');
                 $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
                 $build[$key]['#label_display'] = 'hidden';
             }
         }
         $build = array('#markup' => drupal_html_to_text(drupal_render($build)));
     }
     return $build;
 }
Beispiel #2
1
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     if ($view_mode == 'mail') {
         // Convert field labels into headings.
         // @todo Improve \Drupal\Core\Mail\MailFormatHelper::htmlToText() to
         // convert DIVs correctly.
         foreach (Element::children($build) as $key) {
             if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
                 $build[$key] += array('#prefix' => '');
                 $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
                 $build[$key]['#label_display'] = 'hidden';
             }
         }
         $build['#post_render'][] = function ($html, array $elements) {
             return MailFormatHelper::htmlToText($html);
         };
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     parent::alterBuild($build, $entity, $display, $view_mode);
     if ($entity->id()) {
         $build['#contextual_links']['access_token'] = array('route_parameters' => array('access_token' => $entity->id()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     // Attach campaign JS and CSS.
     $build['#attached']['library'][] = 'mailchimp_campaign/campaign-view';
     // Prepare rendered content.
     /* @var $entity \Drupal\mailchimp_campaign\Entity\MailchimpCampaign */
     $content = $this->renderTemplate($entity->getTemplate());
     $rendered = '';
     foreach ($content as $key => $section) {
         $rendered .= "<h3>{$key}</h3>" . $section;
     }
     // Get the template name.
     $mc_template = mailchimp_campaign_get_template($entity->mc_data['template_id']);
     $mc_template_name = isset($mc_template) ? $mc_template['name'] : '';
     $list_segment_name = 'N/A';
     $list_segments = mailchimp_campaign_get_list_segments($entity->list['id'], 'saved');
     if (isset($entity->mc_data['saved_segment']['id'])) {
         foreach ($list_segments as $list_segment) {
             if ($list_segment['id'] == $entity->mc_data['saved_segment']['id']) {
                 $list_segment_name = $list_segment['name'];
             }
         }
     }
     $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $entity->list['web_id'], array('attributes' => array('target' => '_blank')));
     $archive_url = Url::fromUri($entity->mc_data['archive_url']);
     $fields = array('subject' => array('label' => t('Subject'), 'value' => $entity->mc_data['subject']), 'list' => array('label' => t('MailChimp List'), 'value' => \Drupal::l($entity->list['name'], $list_url)), 'list_segment' => array('label' => t('List Segment'), 'value' => $list_segment_name), 'from_email' => array('label' => t('From Email'), 'value' => $entity->mc_data['from_email']), 'from_name' => array('label' => t('From Name'), 'value' => $entity->mc_data['from_name']), 'template' => array('label' => t('Template'), 'value' => $mc_template_name), 'type' => array('label' => t('List type'), 'value' => $entity->mc_data['type']), 'status' => array('label' => t('Status'), 'value' => $entity->mc_data['status']), 'emails_sent' => array('label' => t('Emails sent'), 'value' => $entity->mc_data['emails_sent']), 'send_time' => array('label' => t('Send time'), 'value' => $entity->mc_data['send_time']), 'content' => array('label' => t('Rendered template HTML (!archive)', array('!archive' => \Drupal::l('View MailChimp archive', $archive_url, array('attributes' => array('target' => '_blank'))))), 'value' => $rendered));
     foreach ($fields as $key => $field) {
         $build[$key] = array('#prefix' => "<div class=\"field campaign-{$key}\"><h3 class=\"field-label\">{$field['label']}</h3>", '#markup' => "<p>{$field['value']}</p>", '#suffix' => '</div>');
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL)
 {
     parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
     // Add contextual links for this custom block.
     if (!$entity->isNew() && $view_mode == 'full') {
         $build['#contextual_links']['block_content'] = array('route_parameters' => array('block_content' => $entity->id()), 'metadata' => array('changed' => $entity->getChangedTime()));
     }
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     parent::alterBuild($build, $entity, $display, $view_mode);
     if (!$entity->isNew()) {
         $build['#contextual_links']['component'] = array('route_parameters' => array('component' => $entity->id()), 'metadata' => array('changed' => $entity->getChangedTime()));
         $build['#theme'] = 'component';
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
     foreach ($entities as $id => $entity) {
         $build[$id]['label'] = array('#weight' => -100, '#markup' => String::checkPlain($entity->label()));
         $build[$id]['separator'] = array('#weight' => -150, '#markup' => ' | ');
         $build[$id]['view_mode'] = array('#weight' => -200, '#markup' => String::checkPlain($view_mode));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
   $build = parent::getBuildDefaults($entity, $view_mode);
   // The message fields are individually rendered into email templates, so
   // the entity has no template itself.
   // @todo  Remove this when providing a template in
   // https://www.drupal.org/node/2722501.
   unset($build['#theme']);
   return $build;
 }
 /**
  * {@inheritdoc}
  */
 protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode)
 {
     $defaults = parent::getBuildDefaults($entity, $view_mode, $langcode);
     // Use a different template for the summary view mode.
     if ($view_mode == 'summary') {
         $defaults['#theme'] = 'aggregator_summary_item';
     }
     return $defaults;
 }
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
     foreach ($entities as $id => $entity) {
         $bundle = $entity->bundle();
         $display = $displays[$bundle];
         if ($display->getComponent('description')) {
             $build[$id]['description'] = array('#markup' => aggregator_filter_xss($entity->getDescription()), '#prefix' => '<div class="item-description">', '#suffix' => '</div>');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     parent::buildContent($entities, $displays, $view_mode, $langcode);
     foreach ($entities as $product) {
         $product->content['qty'] = array('#theme' => 'uc_qty', '#qty' => $product->qty->value, '#cell_attributes' => array('class' => array('qty')));
         $node = node_load($product->nid->target_id);
         $title = $node->access('view') ? \Drupal::l($product->title->value, new Url('entity.node.canonical', array('node' => $product->nid->target_id))) : $product->title->value;
         $product->content['product'] = array('#markup' => $title . uc_product_get_description($product), '#cell_attributes' => array('class' => array('product')));
         $product->content['model'] = array('#markup' => $product->model->value, '#cell_attributes' => array('class' => array('sku')));
         $account = \Drupal::currentUser();
         if ($account->hasPermission('administer products')) {
             $product->content['cost'] = array('#theme' => 'uc_price', '#price' => $product->cost->value, '#cell_attributes' => array('class' => array('cost')));
         }
         $product->content['price'] = array('#theme' => 'uc_price', '#price' => $product->price->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('price')));
         $product->content['total'] = array('#theme' => 'uc_price', '#price' => $product->price->value * $product->qty->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('total')));
     }
 }
Beispiel #12
0
 /**
  * @inheritdoc
  */
 public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     // If we can get domain_field_extra_fields() working here, we may not even
     // need this override class and can do everything via formatters.
     parent::buildContent($entities, $displays, $view_mode, $langcode);
     $fields = domain_field_extra_fields();
     $list = array_keys($fields['domain']['domain']['display']);
     foreach ($entities as $entity) {
         // Add the fields.
         // @TODO: get field sort order.
         $display = $displays[$entity->bundle()];
         foreach ($list as $key) {
             if (!empty($entity->{$key}) && $display->getComponent($key)) {
                 $class = str_replace('_', '-', $key);
                 $entity->content[$key] = array('#markup' => SafeMarkup::checkPlain($entity->{$key}), '#prefix' => '<div class="domain-' . $class . '">' . '<strong>' . SafeMarkup::checkPlain($key) . ':</strong><br />', '#suffix' => '</div>');
             }
         }
     }
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode);
     foreach ($entities as $id => $entity) {
         $bundle = $entity->bundle();
         $display = $displays[$bundle];
         if ($display->getComponent('items')) {
             // When in summary view mode, respect the list_max setting.
             $limit = $view_mode == 'summary' ? $this->config->get('source.list_max') : 20;
             // Retrieve the items attached to this feed.
             $items = $this->entityManager->getStorage('aggregator_item')->loadByFeed($entity->id(), $limit);
             $build[$id]['items'] = $this->entityManager->getViewBuilder('aggregator_item')->viewMultiple($items, $view_mode, $entity->language()->getId());
             if ($view_mode == 'full') {
                 // Also add the pager.
                 $build[$id]['pager'] = array('#type' => 'pager');
             }
         }
         if ($display->getComponent('description')) {
             $build[$id]['description'] = array('#markup' => $entity->getDescription(), '#allowed_tags' => _aggregator_allowed_tags(), '#prefix' => '<div class="feed-description">', '#suffix' => '</div>');
         }
         if ($display->getComponent('image')) {
             $image_link = array();
             // Render the image as link if it is available.
             $image = $entity->getImage();
             $label = $entity->label();
             $link_href = $entity->getWebsiteUrl();
             if ($image && $label && $link_href) {
                 $link_title = array('#theme' => 'image', '#uri' => $image, '#alt' => $label);
                 $image_link = array('#type' => 'link', '#title' => $link_title, '#url' => Url::fromUri($link_href), '#options' => array('attributes' => array('class' => array('feed-image'))));
             }
             $build[$id]['image'] = $image_link;
         }
         if ($display->getComponent('feed_icon')) {
             $build[$id]['feed_icon'] = array('#theme' => 'feed_icon', '#url' => $entity->getUrl(), '#title' => t('@title feed', array('@title' => $entity->label())));
         }
         if ($display->getComponent('more_link')) {
             $title_stripped = strip_tags($entity->label());
             $build[$id]['more_link'] = array('#type' => 'link', '#title' => t('More<span class="visually-hidden"> posts about @title</span>', array('@title' => $title_stripped)), '#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]), '#options' => array('attributes' => array('title' => $title_stripped)));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode);
     $panes = $this->orderPaneManager->getPanes();
     $components = $displays['uc_order']->getComponents();
     foreach ($entities as $id => $order) {
         foreach ($panes as $pane_id => $pane) {
             // Skip panes that are hidden in "Manage display".
             if (!isset($components[$pane_id])) {
                 continue;
             }
             if ($contents = $pane->view($order, $view_mode)) {
                 $build[$id][$pane_id] = array('#prefix' => '<div class="order-pane ' . $pane->getClasses() . '" id="order-pane-' . $pane_id . '">', '#suffix' => '</div>');
                 if ($title = $pane->getTitle()) {
                     $build[$id][$pane_id]['title'] = array('#prefix' => '<div class="order-pane-title">', '#markup' => $title . ':', '#suffix' => '</div>');
                 }
                 $build[$id][$pane_id]['pane'] = $contents;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
     // TODO: Change the autogenerated stub
     foreach ($entities as $id => $order) {
         $panes = _uc_order_pane_list($view_mode);
         foreach ($panes as $pane) {
             if (in_array($view_mode, $pane['show'])) {
                 $func = $pane['callback'];
                 if (function_exists($func) && ($contents = $func($view_mode, $order)) != NULL) {
                     $title = isset($pane['display title']) ? $pane['display title'] : $pane['title'];
                     if ($title) {
                         $title = array('#markup' => $pane['title'] . ':', '#prefix' => '<div class="order-pane-title">', '#suffix' => '</div>');
                     } else {
                         $title = array();
                     }
                     $build[$id][$pane['id']] = array('#prefix' => '<div class="order-pane ' . $pane['class'] . '" id="order-pane-' . $pane['id'] . '">', '#suffix' => '</div>');
                     $build[$id][$pane['id']]['title'] = $title;
                     $build[$id][$pane['id']]['pane'] = $contents;
                 }
             }
         }
     }
 }
Beispiel #16
0
 /**
  * Tests the tag cache plugin.
  */
 public function testTagCaching()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $view = Views::getView('test_tag_cache');
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Saving the view should invalidate the tags.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $view->storage->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after the view is saved.');
     $this->assertFalse($this->getRenderCache($view), 'Output cache empty after the view is saved.');
     $view->destroy();
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Test invalidating the nodes in this view invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $this->nodeViewBuilder->resetCache($this->pages);
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after resetCache is called with pages.');
     $this->assertFalse($this->getRenderCache($view), 'Output cache empty after resetCache is called with pages.');
     $view->destroy();
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Test saving a node in this view invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $node = reset($this->pages);
     $node->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after a page node is saved.');
     $this->assertFalse($this->getRenderCache($view), 'Output cache empty after a page node is saved.');
     $view->destroy();
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Test saving a node not in this view invalidates the cache too.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $this->article->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after an article node is saved.');
     $this->assertFalse($this->getRenderCache($view), 'Output cache empty after an article node is saved.');
     $view->destroy();
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Test that invalidating a tag for a user, does not invalidate the cache,
     // as the user entity type will not be contained in the views cache tags.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $this->userViewBuilder->resetCache(array($this->user));
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found after a user is invalidated.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found after a user is invalidated.');
     $view->destroy();
     // Invalidate the views cache tags in order to invalidate the render
     // caching.
     \Drupal::service('cache_tags.invalidator')->invalidateTags($view->storage->getCacheTagsToInvalidate());
     $build = $view->buildRenderable();
     $renderer->renderPlain($build);
     // Test the cacheFlush method invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($this->getRenderCache($view), 'Output cache found.');
     $cache_plugin->cacheFlush();
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after the cacheFlush() method is called.');
     $this->assertFalse($this->getRenderCache($view), 'Output cache empty after the cacheFlush() method is called.');
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL)
 {
     /** @var \Drupal\node\NodeInterface $entity */
     parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
     if ($entity->id()) {
         $build['#contextual_links']['node'] = array('route_parameters' => array('node' => $entity->id()), 'metadata' => array('changed' => $entity->getChangedTime()));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getBuildDefaults(EntityInterface $entity, $view_mode)
 {
     $defaults = parent::getBuildDefaults($entity, $view_mode);
     $defaults['#theme'] = 'profile';
     return $defaults;
 }
Beispiel #19
0
 /**
  * Constructs a new BlockViewBuilder.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type definition.
  * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
  *   The entity manager service.
  * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
  *   The language manager.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler.
  */
 public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler)
 {
     parent::__construct($entity_type, $entity_manager, $language_manager);
     $this->moduleHandler = $module_handler;
 }
Beispiel #20
0
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode)
 {
     parent::alterBuild($build, $comment, $display, $view_mode);
     if (empty($comment->in_preview)) {
         $prefix = '';
         // Add indentation div or close open divs as needed.
         if ($build['#comment_threaded']) {
             $prefix .= $build['#comment_indent'] <= 0 ? str_repeat('</div>', abs($build['#comment_indent'])) : "\n" . '<div class="indented">';
         }
         // Add anchor for each comment.
         $prefix .= "<a id=\"comment-{$comment->id()}\"></a>\n";
         $build['#prefix'] = $prefix;
         // Close all open divs.
         if (!empty($build['#comment_indent_final'])) {
             $build['#suffix'] = str_repeat('</div>', $build['#comment_indent_final']);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     /** @var \Drupal\node\NodeInterface $entity */
     parent::alterBuild($build, $entity, $display, $view_mode);
     if ($entity->id()) {
         if ($entity->isDefaultRevision()) {
             $build['#contextual_links']['node'] = ['route_parameters' => ['node' => $entity->id()], 'metadata' => ['changed' => $entity->getChangedTime()]];
         } else {
             $build['#contextual_links']['node_revision'] = ['route_parameters' => ['node' => $entity->id(), 'node_revision' => $entity->getRevisionId()], 'metadata' => ['changed' => $entity->getChangedTime()]];
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL)
 {
     parent::alterBuild($build, $comment, $display, $view_mode, $langcode);
     if (empty($comment->in_preview)) {
         $prefix = '';
         $commented_entity = $comment->getCommentedEntity();
         $field_definition = $this->entityManager->getFieldDefinitions($commented_entity->getEntityTypeId(), $commented_entity->bundle())[$comment->getFieldName()];
         $is_threaded = isset($comment->divs) && $field_definition->getSetting('default_mode') == CommentManagerInterface::COMMENT_MODE_THREADED;
         // Add indentation div or close open divs as needed.
         if ($is_threaded) {
             $build['#attached']['css'][] = drupal_get_path('module', 'comment') . '/css/comment.theme.css';
             $prefix .= $comment->divs <= 0 ? str_repeat('</div>', abs($comment->divs)) : "\n" . '<div class="indented">';
         }
         // Add anchor for each comment.
         $prefix .= "<a id=\"comment-{$comment->id()}\"></a>\n";
         $build['#prefix'] = $prefix;
         // Close all open divs.
         if ($is_threaded && !empty($comment->divs_final)) {
             $build['#suffix'] = str_repeat('</div>', $comment->divs_final);
         }
     }
 }
Beispiel #23
0
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL)
 {
     parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
     $build['#contextual_links']['taxonomy_term'] = array('route_parameters' => array('taxonomy_term' => $entity->id()), 'metadata' => array('changed' => $entity->getChangedTime()));
 }
 /**
  * Tests the tag cache plugin.
  */
 public function testTagCaching()
 {
     $view = Views::getView('test_tag_cache');
     $view->render();
     // Saving the view should invalidate the tags.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $view->storage->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after the view is saved.');
     $this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after the view is saved.');
     $view->destroy();
     $view->render();
     // Test invalidating the nodes in this view invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $this->nodeViewBuilder->resetCache($this->pages);
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after resetCache is called with pages.');
     $this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after resetCache is called with pages.');
     $view->destroy();
     $view->render();
     // Test saving a node in this view invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $node = reset($this->pages);
     $node->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after a page node is saved.');
     $this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after a page node is saved.');
     $view->destroy();
     $view->render();
     // Test saving a node not in this view invalidates the cache too.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $this->article->save();
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after an article node is saved.');
     $this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after an article node is saved.');
     $view->destroy();
     $view->render();
     // Test that invalidating a tag for a user, does not invalidate the cache,
     // as the user entity type will not be contained in the views cache tags.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $this->userViewBuilder->resetCache(array($this->user));
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found after a user is invalidated.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found after a user is invalidated.');
     $view->destroy();
     $view->render();
     // Test the cacheFlush method invalidates the cache.
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
     $this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
     $cache_plugin->cacheFlush();
     $cache_plugin = $view->display_handler->getPlugin('cache');
     $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after the cacheFlush() method is called.');
     $this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after the cacheFlush() method is called.');
 }
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     /** @var \Drupal\support_ticket\SupportTicketInterface $entity */
     parent::alterBuild($build, $entity, $display, $view_mode);
     if ($entity->id()) {
         $build['#contextual_links']['support_ticket'] = array('route_parameters' => array('support_ticket' => $entity->id()), 'metadata' => array('changed' => $entity->getChangedTime()));
     }
 }
Beispiel #26
0
 /**
  * {@inheritdoc}
  */
 protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode)
 {
     $defaults = parent::getBuildDefaults($entity, $view_mode, $langcode);
     // $defaults['#theme'] = 'feeds_feed_source';
     return $defaults;
 }