/**
  * Determine if a user can view a given registration node.
  *
  * The user may view the node if they are the creator of it, or if they are
  * an admin.
  *
  * @param \Drupal\node\NodeInterface $node
  * @param \Drupal\Core\Session\AccountInterface $account
  * @return \Drupal\Core\Access\AccessResult
  */
 public function canViewRegistration(\Drupal\node\NodeInterface $node, \Drupal\Core\Session\AccountInterface $account)
 {
     if ($account->hasPermission('administer content')) {
         return \Drupal\Core\Access\AccessResult::allowed();
     }
     if ($node->getOwner()->getAccountName() === $account->getAccountName()) {
         return \Drupal\Core\Access\AccessResult::allowed();
     }
     return \Drupal\Core\Access\AccessResult::forbidden();
 }
示例#2
0
 public function nodeGreeting(NodeInterface $node)
 {
     if ($node->isPublished()) {
         $formatted = $node->body->processed;
         foreach ($node->field_tags as $tag) {
             $terms[] = $tag->entity->label();
         }
         return ['#theme' => 'greeting_node', '#title' => $node->label() . ' (' . $node->bundle() . ')', '#body' => $formatted, '#name' => $node->getOwner()->label(), '#terms' => $terms];
     }
     return ['#markup' => $this->t('Not published')];
 }
示例#3
0
 public function nodeHug(NodeInterface $node)
 {
     if ($node->isPublished()) {
         // These are the same!
         $body = $node->body->value;
         $body = $node->body[0]->value;
         // But we really want...
         $formatted = $node->body->processed;
         $terms = [];
         foreach ($node->field_tags as $tag) {
             $terms[] = $tag->entity->label();
         }
         $message = $this->t('Everyone hug @name because @reasons!', ['@name' => $node->getOwner()->label(), '@reasons' => implode(', ', $terms)]);
         return ['#title' => $node->label() . ' (' . $node->bundle() . ')', '#markup' => $message . $formatted];
     }
     return $this->t('Not published');
 }
 /**
  * Discussed at 47:00 in https://www.youtube.com/watch?v=8vwC_01KFLo
  * @param NodeInterface $node
  * @return type
  */
 public function nodeMyHug(NodeInterface $node)
 {
     if ($node->isPublished()) {
         // These are the same!  BUT DO NOT USE! (See below)
         $body = $node->body->value;
         // works even when body is multi-valued (gets the first one)
         $body = $node->body[0]->value;
         // works even when body is single-valued (gets the only one)
         // But we really want the processed value, which has been run through drupal's filters
         $formatted = $node->body->processed;
         $terms = [];
         foreach ($node->field_tags as $tag) {
             $terms[] = $tag->entity->label();
         }
         $message = $this->t('Everyone give @name a my_hug because @reasons!', ['@name' => $node->getOwner()->label(), '@reasons' => implode(', ', $terms)]);
         return ['#title' => $node->label() . ' (' . $node->bundle() . ')', '#markup' => $message . $formatted];
     }
     return $this->t('Not published');
 }