/**
  * {@inheritdoc}
  *
  * When the $operation is 'add' then the $entity is of type 'profile_type',
  * otherwise $entity is of type 'profile'.
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $account = $this->prepareUser($account);
     $user_page = \Drupal::request()->attributes->get('user');
     // Some times, operation edit is called update.
     // Use edit in any case.
     if ($operation == 'update') {
         $operation = 'edit';
     }
     // Check that if profile type has require roles, the user the profile is
     // being added to has any of the required roles.
     if ($entity->getEntityTypeId() == 'profile') {
         $profile_roles = ProfileType::load($entity->bundle())->getRoles();
         $user_roles = $entity->getOwner()->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     } elseif ($entity->getEntityTypeId() == 'profile_type') {
         $profile_roles = $entity->getRoles();
         $user_roles = User::load($user_page->id())->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     }
     if ($account->hasPermission('bypass profile access')) {
         return AccessResult::allowed()->cachePerPermissions();
     } elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
         return AccessResult::allowed()->cachePerPermissions();
     } else {
         return AccessResult::forbidden()->cachePerPermissions();
     }
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\commerce_order\Entity\Order */
     $orderType = OrderType::load($entity->bundle());
     $row = ['order_id' => $entity->id(), 'type' => $orderType->label(), 'customer' => ['data' => ['#theme' => 'username', '#account' => $entity->getOwner()]], 'state' => $entity->getState()->getLabel(), 'created' => $this->dateFormatter->format($entity->getCreatedTime(), 'short')];
     return $row + parent::buildRow($entity);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $uri = $entity->urlInfo();
     $options = $uri->getOptions();
     $uri->setOptions($options);
     $row['title']['data'] = ['#type' => 'link', '#title' => $entity->label(), '#url' => $uri];
     $row['type'] = SafeMarkup::checkPlain($entity->getType()->label());
     $row['author']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['imported'] = $this->dateFormatter->format($entity->getImportedTime(), 'short');
     $row['operations']['data'] = $this->buildOperations($entity);
     return $row + parent::buildRow($entity);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['name']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['display_name'] = $entity->getDisplayName();
     $row['grade_aggregation_type'] = $entity->getGradeAggregationType();
     $row['exclude_empty'] = $entity->getExcludeEmpty() ? t('Yes') : t('No');
     $row['drop_lowest'] = $entity->getDropLowest();
     $row['author']['data'] = array('#theme' => 'username', '#account' => $entity->getOwner());
     return $row + parent::buildRow($entity);
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\profile\Entity\ProfileInterface $entity */
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : [];
     $uri->setOptions($options);
     $row['label'] = $entity->link();
     $row['type'] = $entity->getType();
     $row['owner']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['is_default'] = $entity->isDefault() ? $this->t('default') : $this->t('not default');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     return $row + parent::buildRow($entity);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\profile\Entity\ProfileInterface $entity */
     $mark = ['#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime())];
     $langcode = $entity->language()->id;
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : [];
     $uri->setOptions($options);
     $row['label']['data'] = ['#type' => 'link', '#title' => $entity->label(), '#suffix' => ' ' . $this->renderer->render($mark)] + $uri->toRenderArray();
     $row['type'] = $entity->getType()->id();
     $row['owner']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     $route_params = ['user' => $entity->getOwnerId(), 'type' => $entity->bundle(), 'profile' => $entity->id()];
     $links['edit'] = ['title' => t('Edit'), 'route_name' => 'entity.profile.edit_form', 'route_parameters' => $route_params];
     $links['delete'] = ['title' => t('Delete'), 'route_name' => 'entity.profile.delete_form', 'route_parameters' => $route_params];
     $row[] = ['data' => ['#type' => 'operations', '#links' => $links]];
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function getAuthor()
 {
     return $this->translation->hasField('content_translation_uid') ? $this->translation->get('content_translation_uid')->entity : $this->translation->getOwner();
 }
 /**
  * {@inheritdoc}
  *
  * @todo D8-port: add D7-theming to TransitionListBuilder.
  */
 public function buildRow(EntityInterface $transition)
 {
     // Show the history table.
     $current_themed = FALSE;
     /* @var $transition WorkflowTransitionInterface */
     $entity = $transition->getTargetEntity();
     $field_name = $transition->getFieldName();
     $current_sid = workflow_node_current_state($entity, $field_name);
     $to_state = $transition->getToState();
     if (!$to_state) {
         // This is an invalid/deleted state.
         $to_label = WORKFLOW_MARK_STATE_IS_DELETED;
         // Add a footer to explain the addition.
         $this->footer_needed = TRUE;
     } else {
         $label = Html::escape($this->t($to_state->label()));
         if ($transition->getToSid() == $current_sid && $to_state->isActive() && !$current_themed) {
             $to_label = $label;
             if (!$current_themed) {
                 // Make a note that we have themed the current state; other times in the history
                 // of this entity where the entity was in this state do not need to be specially themed.
                 $current_themed = TRUE;
             }
         } elseif (!$to_state->isActive()) {
             $to_label = $label . WORKFLOW_MARK_STATE_IS_DELETED;
             // Add a footer to explain the addition.
             $this->footer_needed = TRUE;
         } else {
             // Regular state.
             $to_label = $label;
         }
     }
     unset($to_state);
     // Not needed anymore.
     $from_state = $transition->getFromState();
     if (!$from_state) {
         // This is an invalid/deleted state.
         $from_label = WORKFLOW_MARK_STATE_IS_DELETED;
         // Add a footer to explain the addition.
         $this->footer_needed = TRUE;
     } else {
         $label = Html::escape($this->t($from_state->label()));
         if (!$from_state->isActive()) {
             $from_label = $label . WORKFLOW_MARK_STATE_IS_DELETED;
             // Add a footer to explain the addition.
             $this->footer_needed = TRUE;
         } else {
             // Regular state.
             $from_label = $label;
         }
     }
     unset($from_state);
     // Not needed anymore.
     $owner = $transition->getOwner();
     $field_name = $transition->getFieldName();
     $field_label = $transition->getFieldName();
     $variables = array('transition' => $transition, 'extra' => '', 'from_label' => $from_label, 'to_label' => $to_label, 'user' => $owner);
     // Allow other modules to modify the row.
     \Drupal::moduleHandler()->alter('workflow_history', $variables);
     //     'class' => array('workflow_history_row'), // TODO D8-port
     $row['timestamp']['data'] = $transition->getTimestampFormatted();
     // 'class' => array('timestamp')
     // html_entity_decode() transforms chars like '&' correctly.
     if ($this->showColumnFieldname($entity)) {
         $row['field_name']['data'] = html_entity_decode($field_label);
     }
     $row['from_state']['data'] = html_entity_decode($from_label);
     // 'class' => array('previous-state-name'))
     $row['to_state']['data'] = html_entity_decode($to_label);
     // 'class' => array('state-name'))
     $row['user_name']['data'] = $owner->getUsername();
     // 'class' => array('user-name')
     $row['comment']['data'] = html_entity_decode($transition->getComment());
     // 'class' => array('log-comment')
     //    $row['comment'] = array(
     //      '#type' => 'textarea',
     //      '#default_value' => $transition->getComment(),
     //    );
     // Column 'Operations' is now added by core.
     // D7: $row['operations']['data'] = $this->buildOperations($entity);
     $row += parent::buildRow($transition);
     return $row;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 protected function entitySaveAccess(EntityInterface $entity)
 {
     // No need to authorize.
     if (!$this->configuration['authorize'] || !$entity instanceof EntityOwnerInterface) {
         return;
     }
     // If the uid was mapped directly, rather than by email or username, it
     // could be invalid.
     if (!($account = $entity->getOwner())) {
         throw new EntityAccessException($this->t('Invalid user mapped to %label.', ['%label' => $entity->label()]));
     }
     // We don't check access for anonymous users.
     if ($account->isAnonymous()) {
         return;
     }
     $op = $entity->isNew() ? 'create' : 'update';
     // Access granted.
     if ($entity->access($op, $account)) {
         return;
     }
     $args = ['%name' => $account->getUsername(), '@op' => $op, '@bundle' => $this->getItemLabelPlural()];
     throw new EntityAccessException($this->t('User %name is not authorized to @op @bundle.', $args));
 }
예제 #10
0
  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /* @var $entity \Drupal\commerce_payment\Entity\PaymentInfo */
    $paymentInfoType = PaymentInfoType::load($entity->bundle());

    $row = array(
      'information_id' => $entity->id(),
      'payment_method' => $paymentInfoType->label(),
      'owner' => array(
        'data' => array(
          '#theme' => 'username',
          '#account' => $entity->getOwner(),
        ),
      ),
      'status' => $entity->getStatus(),
      'created' => $this->dateFormatter->format($entity->getCreatedTime(), 'short'),
      'changed' => $this->dateFormatter->format($entity->getChangedTime(), 'short'),
    );
    return $row + parent::buildRow($entity);
  }
 /**
  * {@inheritdnoc}
  */
 public function buildRow(EntityInterface $payment)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $row['data']['updated'] = $this->dateFormatter->format($payment->getChangedTime());
     $status_definition = $payment->getPaymentStatus()->getPluginDefinition();
     $row['data']['status'] = $status_definition['label'];
     /** @var \Drupal\currency\Entity\CurrencyInterface $currency */
     $currency = $this->currencyStorage->load($payment->getCurrencyCode());
     if (!$currency) {
         $currency = $this->currencyStorage->load('XXX');
     }
     $row['data']['amount'] = $currency->formatAmount($payment->getAmount());
     $row['data']['payment_method'] = $payment->getPaymentMethod() ? $payment->getPaymentMethod()->getPluginDefinition()['label'] : $this->t('Unavailable');
     $row['data']['owner']['data'] = array('#theme' => 'username', '#account' => $payment->getOwner());
     $operations = $this->buildOperations($payment);
     $row['data']['operations']['data'] = $operations;
     return $row;
 }