本文整理汇总了PHP中Drupal\node\NodeInterface::getOwner方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getOwner方法的具体用法?PHP NodeInterface::getOwner怎么用?PHP NodeInterface::getOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getOwner方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canViewRegistration
/**
* 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: nodeGreeting
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: nodeHug
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');
}
示例4: nodeMyHug
/**
* 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');
}