php Drupal-Core-Entity-EntityInterface类(方法)实例源码

下面列出了php Drupal-Core-Entity-EntityInterface 类(方法)源码代码实例,从而了解它的用法。

作者:mglama    项目:drupalcamp-bas   
/**
  * Entity builder: updates the product status with the submitted value.
  *
  * @param string $entity_type
  *   The entity type.
  * @param \Drupal\commerce_product\Entity\ProductInterface $entity
  *   The product updated with the submitted values.
  * @param array $form
  *   The complete form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @see \Drupal\node\NodeForm::form()
  */
 public static function updateStatus($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     $element = $form_state->getTriggeringElement();
     if (isset($element['#published_status'])) {
         $entity->setPublished($element['#published_status']);
     }
 }

作者:ashkarrrahma    项目:bran   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\brand\Entity\brand */
     $row['id'] = $entity->id();
     $row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.brand.edit_form', array('brand' => $entity->id())));
     return $row + parent::buildRow($entity);
 }

作者:alnutil    项目:drunatr   
/**
  * Alters the field to render a link.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  * @param \Drupal\views\ResultRow $values
  *   The current row of the views result.
  *
  * @return string
  *   The acutal rendered text (without the link) of this field.
  */
 protected function renderLink(EntityInterface $entity, ResultRow $values)
 {
     $text = !empty($this->options['text']) ? $this->options['text'] : t('View');
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = $entity->getSystemPath();
     return $text;
 }

作者:318i    项目:318-i   
/**
  * {@inheritdoc}
  */
 public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = array())
 {
     $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation);
     $form_object->setEntity($entity);
     $form_state = (new FormState())->setFormState($form_state_additions);
     return $this->formBuilder->buildForm($form_object, $form_state);
 }

作者:housineal    项目:drpl8_d   
/**
  * Prepares the link to the profile.
  *
  * @param \Drupal\Core\Entity\EntityInterface $profile
  *   The profile entity this field belongs to.
  * @param ResultRow $values
  *   The values retrieved from the view's result set.
  *
  * @return string
  *   Returns a string for the link text.
  */
 protected function renderLink($profile, ResultRow $values) {
   if ($profile->access('view')) {
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = 'profile/' . $profile->id();
     return $profile->label();
   }
 }

作者:darrylr    项目:protovbmwm   
/**
  * Renders the Metatag defaults lable plus its configuration.
  *
  * @param EntityInterface $entity
  *   The Metatag defaults entity.
  * @return
  *   Render array for a table cell.
  */
 public function getLabelAndConfig(EntityInterface $entity)
 {
     $output = '<div>';
     $prefix = '';
     $inherits = '';
     if ($entity->id() != 'global') {
         $prefix = '<div class="indentation"></div>';
         $inherits .= 'Global';
     }
     if (strpos($entity->id(), '__') !== FALSE) {
         $prefix .= '<div class="indentation"></div>';
         list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
         $inherits .= ', ' . $entity_label;
     }
     $output .= '<div>
               <p>Inherits meta tags from: ' . $inherits . '</p>
             </div>';
     $tags = $entity->get('tags');
     if (count($tags)) {
         $output .= '<table>
                 <tbody>';
         foreach ($tags as $tag_id => $tag_value) {
             $output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
         }
         $output .= '</tbody></table>';
     }
     $output .= '</div></div>';
     return array('data' => array('#type' => 'details', '#prefix' => $prefix, '#title' => $this->getLabel($entity), 'config' => array('#markup' => $output)));
 }

作者:joka    项目:d8.de   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\eck\Entity\EckEntity */
     $row['id'] = $entity->id();
     $row['title'] = \Drupal::l($this->getLabel($entity), Url::fromRoute('entity.' . $this->entityTypeId . '.canonical', array($this->entityTypeId => $entity->id())));
     return array_merge($row, parent::buildRow($entity));
 }

作者:vinhgian    项目:Learning-Drupal-   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\my_first_entity\Entity\Course */
     $row['id'] = $entity->id();
     $row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.course.edit_form', array('course' => $entity->id())));
     return $row + parent::buildRow($entity);
 }

作者:anatalsce    项目:en-class   
/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     if ($operation == 'delete' && $entity->getFieldStorageDefinition()->isLocked()) {
         return FALSE;
     }
     return $account->hasPermission('administer ' . $entity->entity_type . ' fields');
 }

作者:emilienGalle    项目:DrupalUnice   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     // You probably want a few more properties here...
     return $row + parent::buildRow($entity);
 }

作者:eigento    项目:tommiblo   
/**
  * {@inheritdoc}
  */
 public function isModeratedEntity(EntityInterface $entity)
 {
     if (!$entity instanceof ContentEntityInterface) {
         return FALSE;
     }
     return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle());
 }

作者:nishantkumar15    项目:drupal8.crackl   
/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $payment, $operation, AccountInterface $account)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     if ($operation == 'update_status') {
         $payment_method = $payment->getPaymentMethod();
         if ($payment_method instanceof PaymentMethodUpdatePaymentStatusInterface && !$payment_method->updatePaymentStatusAccess($account)) {
             return AccessResult::forbidden();
         }
     } elseif ($operation == 'capture') {
         $payment_method = $payment->getPaymentMethod();
         if ($payment_method instanceof PaymentMethodCapturePaymentInterface) {
             return AccessResult::allowedIf($payment_method instanceof PaymentMethodCapturePaymentInterface)->andIf(AccessResult::allowedIf($payment_method->capturePaymentAccess($account)))->andIf($this->checkAccessPermission($payment, $operation, $account));
         }
         return AccessResult::forbidden();
     } elseif ($operation == 'refund') {
         $payment_method = $payment->getPaymentMethod();
         if ($payment_method instanceof PaymentMethodRefundPaymentInterface) {
             return AccessResult::allowedIf($payment_method->refundPaymentAccess($account))->andIf($this->checkAccessPermission($payment, $operation, $account));
         }
         return AccessResult::forbidden();
     } elseif ($operation == 'complete') {
         if ($payment->getPaymentMethod()) {
             return AccessResult::allowedIf($payment->getOwnerId() == $account->id())->orIf(AccessResult::forbiddenIf($payment->getPaymentMethod()->getPaymentExecutionResult()->isCompleted()));
         } else {
             return AccessResult::forbidden();
         }
     }
     return $this->checkAccessPermission($payment, $operation, $account);
 }

作者:joshuataylo    项目:dinod   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\dinodb\Entity\Dinosaur */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($this->getLabel($entity), new Url('entity.dinosaur.edit_form', array('dinosaur' => $entity->id())));
     return $row + parent::buildRow($entity);
 }

作者:davidsoloma    项目:drupalconsole.co   
/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $filter_format, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\filter\FilterFormatInterface $filter_format */
     // All users are allowed to use the fallback filter.
     if ($operation == 'use') {
         if ($filter_format->isFallbackFormat()) {
             return AccessResult::allowed();
         } else {
             return AccessResult::allowedIfHasPermission($account, $filter_format->getPermissionName());
         }
     }
     // The fallback format may not be disabled.
     if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
         return AccessResult::forbidden();
     }
     // We do not allow filter formats to be deleted through the UI, because that
     // would render any content that uses them unusable.
     if ($operation == 'delete') {
         return AccessResult::forbidden();
     }
     if (in_array($operation, array('disable', 'update'))) {
         return parent::checkAccess($filter_format, $operation, $langcode, $account);
     }
     // No opinion.
     return AccessResult::neutral();
 }

作者:darrylr    项目:protovbmwm   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['type'] = $entity->link();
     $row['registration'] = $entity->getRegistration() ? t('Yes') : t('No');
     $row['multiple'] = $entity->getMultiple() ? t('Yes') : t('No');
     return $row + parent::buildRow($entity);
 }

作者:ec-europ    项目:joinup-de   
/**
  * {@inheritdoc}
  */
 public function checkAccess(EntityInterface $entity, Route $route, AccountInterface $account, $operation, $graph_name)
 {
     if (!$entity) {
         return FALSE;
     }
     // For now, we only have the view operation but this is not the only
     // operation so we will check anyway.
     $map = ['view' => 'view all graphs'];
     $entity_type_id = $entity->getEntityTypeId();
     $type_map = ['view' => "view {$entity_type_id} {$graph_name} graph"];
     // If the operation is not supported, do not allow access.
     if (!isset($map[$operation]) || !isset($type_map[$operation])) {
         return FALSE;
     }
     // @todo: This probably needs to be cached manually creating a cid.
     // @see: \Drupal\node\Access\NodeRevisionAccessCheck::checkAccess().
     // @todo: This needs also to check cache for cached permission.
     // @see: \Drupal\Core\Entity\EntityAccessControlHandler::access().
     $has_permission = $account->hasPermission($map[$operation]) || $account->hasPermission($type_map[$operation]);
     $access = $has_permission ? AccessResult::allowed() : AccessResult::neutral();
     $arguments = [$entity, $operation, $account, $graph_name];
     $access_array = array_merge([$access], $this->moduleHandler->invokeAll('entity_graph_access', $arguments), $this->moduleHandler->invokeAll($entity_type_id . '_graph_access', $arguments));
     $return = $this->processAccessHookResults($access_array);
     return $return->isAllowed();
 }

作者:tedbo    项目:scheduled-updates-dem   
/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\scheduled_updates\Entity\ScheduledUpdate */
     $row['name'] = $this->l($entity->label(), new Url('entity.scheduled_update.edit_form', array('scheduled_update' => $entity->id())));
     $row['type'] = $this->updateUtils->getUpdateTypeLabel($entity);
     return $row + parent::buildRow($entity);
 }

作者:Hak    项目:drupal8_trainin   
/**
  * {@inheritdoc}
  */
 public function getTranslationMetadata(EntityInterface $translation)
 {
     // We need a new instance of the metadata handler wrapping each translation.
     $entity_type = $translation->getEntityType();
     $class = $entity_type->get('content_translation_metadata');
     return new $class($translation, $this->getTranslationHandler($entity_type->id()));
 }

作者:jkyt    项目:agol   
/**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    /** @var \Drupal\entityqueue\EntitySubqueueInterface $entity */
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access content');
        break;

      case 'update':
        return AccessResult::allowedIfHasPermissions($account, ["update {$entity->bundle()} entityqueue", 'manipulate all entityqueues', 'administer entityqueue'], 'OR');
        break;

      case 'delete':
        $can_delete_subqueue = AccessResult::allowedIf(!$entity->getQueue()->getHandlerPlugin()->hasAutomatedSubqueues());

        $access_result = AccessResult
          ::allowedIfHasPermissions($account, ["delete {$entity->bundle()} entityqueue", 'manipulate all entityqueues', 'administer entityqueue'], 'OR')
          ->andIf($can_delete_subqueue);

        return $access_result;
        break;

      default:
        // No opinion.
        return AccessResult::neutral();
    }
  }

作者:Nikola-xii    项目:d8intrane   
/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\user\UserInterface $entity*/
     // The anonymous user's profile can neither be viewed, updated nor deleted.
     if ($entity->isAnonymous()) {
         return AccessResult::forbidden();
     }
     // Administrators can view/update/delete all user profiles.
     if ($account->hasPermission('administer users')) {
         return AccessResult::allowed()->cachePerRole();
     }
     switch ($operation) {
         case 'view':
             // Only allow view access if the account is active.
             if ($account->hasPermission('access user profiles') && $entity->isActive()) {
                 return AccessResult::allowed()->cachePerRole()->cacheUntilEntityChanges($entity);
             } else {
                 if ($account->id() == $entity->id()) {
                     return AccessResult::allowed()->cachePerUser();
                 }
             }
             break;
         case 'update':
             // Users can always edit their own account.
             return AccessResult::allowedIf($account->id() == $entity->id())->cachePerUser();
         case 'delete':
             // Users with 'cancel account' permission can cancel their own account.
             return AccessResult::allowedIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerRole()->cachePerUser();
     }
     // No opinion.
     return AccessResult::neutral();
 }


问题


面经


文章

微信
公众号

扫码关注公众号