当前位置: 首页>>代码示例>>PHP>>正文


PHP NodeInterface::isNew方法代码示例

本文整理汇总了PHP中Drupal\node\NodeInterface::isNew方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::isNew方法的具体用法?PHP NodeInterface::isNew怎么用?PHP NodeInterface::isNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\node\NodeInterface的用法示例。


在下文中一共展示了NodeInterface::isNew方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: access

 /**
  * Checks access to the node preview page.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param \Drupal\node\NodeInterface $node_preview
  *   The node that is being previewed.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(AccountInterface $account, NodeInterface $node_preview)
 {
     if ($node_preview->isNew()) {
         $access_controller = $this->entityManager->getAccessControlHandler('node');
         return $access_controller->createAccess($node_preview->bundle(), $account, [], TRUE);
     } else {
         return $node_preview->access('update', $account, TRUE);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:20,代码来源:NodePreviewAccessCheck.php

示例2: addFormElements

 /**
  * {@inheritdoc}
  */
 public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE)
 {
     // If the form is being processed during the Ajax callback of our book bid
     // dropdown, then $form_state will hold the value that was selected.
     if ($form_state->hasValue('book')) {
         $node->book = $form_state->getValue('book');
     }
     $form['book'] = array('#type' => 'details', '#title' => $this->t('Book outline'), '#weight' => 10, '#open' => !$collapsed, '#group' => 'advanced', '#attributes' => array('class' => array('book-outline-form')), '#attached' => array('library' => array('book/drupal.book')), '#tree' => TRUE);
     foreach (array('nid', 'has_children', 'original_bid', 'parent_depth_limit') as $key) {
         $form['book'][$key] = array('#type' => 'value', '#value' => $node->book[$key]);
     }
     $form['book']['pid'] = $this->addParentSelectFormElements($node->book);
     // @see \Drupal\book\Form\BookAdminEditForm::bookAdminTableTree(). The
     // weight may be larger than 15.
     $form['book']['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#default_value' => $node->book['weight'], '#delta' => max(15, abs($node->book['weight'])), '#weight' => 5, '#description' => $this->t('Pages at a given level are ordered first by weight and then by title.'));
     $options = array();
     $nid = !$node->isNew() ? $node->id() : 'new';
     if ($node->id() && $nid == $node->book['original_bid'] && $node->book['parent_depth_limit'] == 0) {
         // This is the top level node in a maximum depth book and thus cannot be
         // moved.
         $options[$node->id()] = $node->label();
     } else {
         foreach ($this->getAllBooks() as $book) {
             $options[$book['nid']] = $book['title'];
         }
     }
     if ($account->hasPermission('create new books') && ($nid == 'new' || $nid != $node->book['original_bid'])) {
         // The node can become a new book, if it is not one already.
         $options = array($nid => $this->t('- Create a new book -')) + $options;
     }
     if (!$node->book['bid']) {
         // The node is not currently in the hierarchy.
         $options = array(0 => $this->t('- None -')) + $options;
     }
     // Add a drop-down to select the destination book.
     $form['book']['bid'] = array('#type' => 'select', '#title' => $this->t('Book'), '#default_value' => $node->book['bid'], '#options' => $options, '#access' => (bool) $options, '#description' => $this->t('Your page will be a part of the selected book.'), '#weight' => -5, '#attributes' => array('class' => array('book-title-select')), '#ajax' => array('callback' => 'book_form_update', 'wrapper' => 'edit-book-plid-wrapper', 'effect' => 'fade', 'speed' => 'fast'));
     return $form;
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:41,代码来源:BookManager.php

示例3: getState

 /**
  * Retrieve the initial state value of the entity.
  *
  * The state_machine module uses a protected property called initialValue to
  * get the initial state which is inaccessible. During an entity update, the
  * typedDataManager attempts to validate the field but the constraint again
  * calls for the Guard to check the allowed states.
  * The issue is that the entity object already carries the new value
  * at this point, so it attempts to check a to_state to to_state transition.
  * In order to check the initial value, we get the unchanged version of the
  * object from the database.
  *
  * @param \Drupal\node\NodeInterface $entity
  *    The node entity.
  *
  * @return string
  *    The machine name value of the state.
  *
  * @see https://www.drupal.org/node/2745673
  */
 protected function getState(NodeInterface $entity)
 {
     if ($entity->isNew()) {
         return $entity->field_news_state->first()->value;
     } else {
         $unchanged_entity = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($entity->id());
         return $unchanged_entity->field_news_state->first()->value;
     }
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:29,代码来源:JoinupNewsFulfillmentGuard.php

示例4: createIndex

 /**
  * {@inheritdoc}
  */
 public function createIndex(NodeInterface $node)
 {
     $query = $this->database->insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
     foreach ($node->getTranslationLanguages() as $langcode => $language) {
         $translation = $node->getTranslation($langcode);
         foreach ($translation->taxonomy_forums as $item) {
             $query->values(array('nid' => $node->id(), 'title' => $translation->label(), 'tid' => $item->target_id, 'sticky' => (int) $node->isSticky(), 'created' => $node->getCreatedTime(), 'comment_count' => 0, 'last_comment_timestamp' => $node->getCreatedTime()));
         }
     }
     $query->execute();
     // The logic for determining last_comment_count is fairly complex, so
     // update the index too.
     if ($node->isNew()) {
         $this->updateIndex($node);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:ForumIndexStorage.php


注:本文中的Drupal\node\NodeInterface::isNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。