/**
  * {@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();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\content_entity_example\Entity\OnlineMessage */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.online_message.edit_form', array('online_message' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * 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)));
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\drupal8_entity\Entity\Drupal8EntityItem */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.drupal8_entity_item.edit_form', array('drupal8_entity_item' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\drupalbristol_sponsors\Entity\SponsorEntity */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.sponsor.edit_form', array('sponsor' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\custom_page\Entity\CustomPage */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.custom_page.canonical', array('custom_page' => $entity->id())));
     $row['uuid'] = $entity->uuid();
     return $row + parent::buildRow($entity);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\component\Entity\Component */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.component.canonical', array('component' => $entity->id())));
     $row['uuid'] = $entity->uuid();
     return $row + parent::buildRow($entity);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     $entity_type_id = $entity->getEntityTypeId();
     if ($entity instanceof ContentEntityInterface && $entity->isDefaultRevision() || !$entity->getEntityType()->isRevisionable()) {
         $build['#contextual_links'][$entity_type_id] = ['route_parameters' => [$entity_type_id => $entity->id()]];
     } else {
         $build['#contextual_links'][$entity_type_id . '_revision'] = ['route_parameters' => [$entity_type_id => $entity->id(), $entity_type_id . '_revision' => $entity->getRevisionId()]];
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     if ($entity->isLocked()) {
         $row['id'] = $this->t('@entity_id (locked)', array('@entity_id' => $entity->id()));
     } else {
         $row['id'] = $entity->id();
     }
     $row['label'] = $this->getLabel($entity);
     $row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
     return $row + parent::buildRow($entity);
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     switch ($operation) {
         case 'delete':
             if ($entity->id() == RoleInterface::ANONYMOUS_ID || $entity->id() == RoleInterface::AUTHENTICATED_ID) {
                 return AccessResult::forbidden();
             }
         default:
             return parent::checkAccess($entity, $operation, $account);
     }
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     switch ($operation) {
         case 'delete':
             if ($entity->id() == DRUPAL_ANONYMOUS_RID || $entity->id() == DRUPAL_AUTHENTICATED_RID) {
                 return FALSE;
             }
         default:
             return parent::checkAccess($entity, $operation, $langcode, $account);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     if ($operation == 'view') {
         // Do not allow access personal category via site-wide route.
         return $account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal';
     } elseif ($operation == 'delete' || $operation == 'update') {
         // Do not allow the 'personal' category to be deleted, as it's used for
         // the personal contact form.
         return $account->hasPermission('administer contact forms') && $entity->id() !== 'personal';
     }
     return parent::checkAccess($entity, $operation, $langcode, $account);
 }
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     if ($operation == 'view') {
         // Do not allow access personal form via site-wide route.
         return AccessResult::allowedIf($account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal')->cachePerPermissions();
     } elseif ($operation == 'delete' || $operation == 'update') {
         // Do not allow the 'personal' form to be deleted, as it's used for
         // the personal contact form.
         return AccessResult::allowedIf($account->hasPermission('administer contact forms') && $entity->id() !== 'personal')->cachePerPermissions();
     }
     return parent::checkAccess($entity, $operation, $account);
 }
Пример #14
0
 /**
  * Check view access.
  *
  * See EntityAccessControllerInterface::view() for parameters.
  */
 protected function viewAccess(EntityInterface $entity, $langcode, AccountInterface $account)
 {
     // Never allow access to view the anonymous user account.
     if ($entity->id()) {
         // Admins can view all, users can view own profiles at all times.
         if ($account->id() == $entity->id() || $account->hasPermission('administer users')) {
             return TRUE;
         } elseif ($account->hasPermission('access user profiles')) {
             // Only allow view access if the account is active.
             return $entity->status->value;
         }
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\checkstyle\Entity\CheckstyleIssue */
     $row['id'] = $this->l($entity->id(), new Url('entity.checkstyle_issue.edit_form', array('checkstyle_issue' => $entity->id())));
     /** @var EntityReferenceFieldItemList $ref_field */
     $ref_field = $entity->get('issue_type');
     /** @var Node $ref_entity */
     $ref_entity = Node::load($ref_field->get(0)->getValue()['target_id']);
     #krumo($ref_entity->get('issue_type')->getValue()[0]['value']);
     #krumo( $ref_entity->get('title'));
     # @todo find decent way of displaying this stuff
     $row['issue_type'] = $ref_entity->get('issue_type')->getValue()[0]['value'];
     return $row + parent::buildRow($entity);
 }
Пример #16
0
 /**
  * Assert that a field has the expected values in an entity.
  *
  * This function only checks a single column in the field values.
  *
  * @param EntityInterface $entity
  *   The entity to test.
  * @param $field_name
  *   The name of the field to test
  * @param $expected_values
  *   The array of expected values.
  * @param $langcode
  *   (Optional) The language code for the values. Defaults to
  *   \Drupal\Core\Language\LanguageInterface::LANGCODE_DEFAULT.
  * @param $column
  *   (Optional) The name of the column to check. Defaults to 'value'.
  */
 function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_DEFAULT, $column = 'value')
 {
     // Re-load the entity to make sure we have the latest changes.
     \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
     $e = entity_load($entity->getEntityTypeId(), $entity->id());
     $field = $values = $e->getTranslation($langcode)->{$field_name};
     // Filter out empty values so that they don't mess with the assertions.
     $field->filterEmptyItems();
     $values = $field->getValue();
     $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
     foreach ($expected_values as $key => $value) {
         $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\simple_oauth\Entity\AccessToken */
     $type = $entity->get('resource')->target_id == 'authentication' ? t('Refresh Token') : t('Access Token');
     $row['type'] = $type;
     $user = $entity->get('auth_user_id')->entity;
     $row['user'] = $this->l($user->label(), new Url('entity.user.canonical', array('user' => $user->id())));
     $owner = $entity->get('user_id')->entity;
     $row['owner'] = $this->l($owner->label(), new Url('entity.user.canonical', array('user' => $owner->id())));
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.access_token.edit_form', array('access_token' => $entity->id())));
     $row['resource'] = $entity->get('resource')->entity->label();
     return $row + parent::buildRow($entity);
 }
Пример #18
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Special case the personal form.
     if ($entity->id() == 'personal') {
         $row['form'] = $entity->label();
         $row['recipients'] = t('Selected user');
         $row['selected'] = t('No');
     } else {
         $row['form'] = $entity->link(NULL, 'canonical');
         $row['recipients']['data'] = ['#theme' => 'item_list', '#items' => $entity->getRecipients(), '#context' => ['list_style' => 'comma-list']];
         $default_form = \Drupal::config('contact.settings')->get('default_form');
         $row['selected'] = $default_form == $entity->id() ? t('Yes') : t('No');
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * {@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);
 }
Пример #20
0
 /**
  * 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();
   }
 }
Пример #21
0
 /**
  * {@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);
 }
Пример #22
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);
 }
Пример #23
0
 /**
  * {@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));
 }
 /**
  * {@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);
 }
Пример #25
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);
 }
 /**
  * {@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();
     }
 }
Пример #27
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);
 }
Пример #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)
 {
     /* @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);
 }
 /**
  * {@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);
 }