コード例 #1
1
 /**
  * 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']);
     }
 }
コード例 #2
0
 /**
  * {@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);
 }
コード例 #3
0
ファイル: Link.php プロジェクト: alnutile/drunatra
 /**
  * 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;
 }
コード例 #4
0
ファイル: EntityFormBuilder.php プロジェクト: 318io/318-io
 /**
  * {@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);
 }
コード例 #5
0
ファイル: Label.php プロジェクト: housineali/drpl8_dv
 /**
  * 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();
   }
 }
コード例 #6
0
 /**
  * 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)));
 }
コード例 #7
0
ファイル: EckEntityListBuilder.php プロジェクト: jokas/d8.dev
 /**
  * {@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));
 }
コード例 #8
0
 /**
  * {@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);
 }
コード例 #9
0
 /**
  * {@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');
 }
コード例 #10
0
 /**
  * {@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);
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function isModeratedEntity(EntityInterface $entity)
 {
     if (!$entity instanceof ContentEntityInterface) {
         return FALSE;
     }
     return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle());
 }
コード例 #12
0
 /**
  * {@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);
 }
コード例 #13
0
 /**
  * {@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);
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $bundle_entity = $this->getBundleEntity();
     $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()];
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('@type %info has been created.', $t_args));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('@type %info has been updated.', $t_args));
     }
     if ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
             $form_state->setRedirectUrl($this->entity->toUrl('collection'));
         } else {
             $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
         }
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
 /**
  * {@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();
 }
コード例 #16
0
 /**
  * {@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);
 }
コード例 #17
0
 /**
  * {@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();
 }
コード例 #18
0
 /**
  * {@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);
 }
コード例 #19
0
 /**
  * {@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()));
 }
コード例 #20
0
  /**
   * {@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();
    }
  }
コード例 #21
0
 /**
  * {@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();
 }
コード例 #22
0
ファイル: EntityRepository.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array())
 {
     $translation = $entity;
     if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
         if (empty($langcode)) {
             $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
             $entity->addCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]);
         }
         // Retrieve language fallback candidates to perform the entity language
         // negotiation, unless the current translation is already the desired one.
         if ($entity->language()->getId() != $langcode) {
             $context['data'] = $entity;
             $context += array('operation' => 'entity_view', 'langcode' => $langcode);
             $candidates = $this->languageManager->getFallbackCandidates($context);
             // Ensure the default language has the proper language code.
             $default_language = $entity->getUntranslated()->language();
             $candidates[$default_language->getId()] = LanguageInterface::LANGCODE_DEFAULT;
             // Return the most fitting entity translation.
             foreach ($candidates as $candidate) {
                 if ($entity->hasTranslation($candidate)) {
                     $translation = $entity->getTranslation($candidate);
                     break;
                 }
             }
         }
     }
     return $translation;
 }
コード例 #23
0
ファイル: LogListBuilder.php プロジェクト: eiriksm/log
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\log\Entity\Log */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($this->getLabel($entity), new Url('entity.log.edit_form', array('log' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $entity */
     $row['name'] = $entity->label();
     $row['tag'] = $entity->getTag();
     return $row + parent::buildRow($entity);
 }
コード例 #25
0
  /**
   * {@inheritdoc}
   */
  public function formElement(EntityInterface $entity) {
    $form = [];

    if ($this->entityTypeManager->getDefinition($entity->getEntityTypeId())->getKey('label')) {
      $form['label'] = array(
        '#type' => 'textfield',
        '#title' => $this->translationManager->translate('New Label'),
        '#maxlength' => 255,
        '#required' => TRUE,
      );
    }

    $form['id'] = array(
      '#type' => 'machine_name',
      '#title' => $this->translationManager->translate('New Id'),
      '#maxlength' => 255,
      '#required' => TRUE,
    );

    // If entity must have a prefix
    // (e.g. entity_form_mode, entity_view_mode, ...).
    if (method_exists($entity, 'getTargetType')) {
      $form['id']['#field_prefix'] = $entity->getTargetType() . '.';
    }

    if (method_exists($entity, 'load')) {
      $form['id']['#machine_name'] = [
        'exists' => get_class($entity) . '::load',
      ];
    }

    return $form;
  }
コード例 #26
0
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     if ($operation == 'delete' && $entity->isLocked()) {
         return FALSE;
     }
     return parent::checkAccess($entity, $operation, $langcode, $account);
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\quiz\Entity\Quiz */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($this->getLabel($entity), new Url('entity.quiz.canonical', array('quiz' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
コード例 #28
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\content_entity_example\Entity\Contact */
     $row['rid'] = $entity->id();
     $row['first_name'] = $entity->first_name->value;
     return $row + parent::buildRow($entity);
 }
コード例 #29
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['id'] = $entity->getId();
     $row['name'] = $this->getLabel($entity);
     $row['tag'] = $entity->getTag();
     return $row + parent::buildRow($entity);
 }
コード例 #30
0
ファイル: KeyListBuilder.php プロジェクト: rlhawk/key
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['provider'] = $this->keyProviderPluginManager->getDefinition($entity->getKeyProvider())['title'];
     $row['service_default'] = $entity->getServiceDefault() ? "Yes" : "No";
     return $row + parent::buildRow($entity);
 }