/**
  * {@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}
  */
 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';
     }
     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();
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['type'] = $entity->getType();
     $row['label'] = $entity->label();
     if ($this->hasConfigurableActions) {
         $row += parent::buildRow($entity);
     }
     return $row;
 }
예제 #4
0
 public function view(EntityInterface $node, $view_mode = 'full', $langcode = NULL)
 {
     // Redirect to the edit path on the discussion type
     if ($node->getType() == 'discussion') {
         $url = Url::fromRoute('entity.node.ahs_discuss', ['node' => $node->id()]);
         return \Drupal::service('entity.form_builder')->getForm($node, 'ahs_discuss');
         //return new RedirectResponse($url->toString());
     } else {
         return parent::view($node, $view_mode, $langcode);
     }
 }
예제 #5
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);
 }
예제 #6
0
 public function view(EntityInterface $node, $view_mode = 'full', $langcode = NULL)
 {
     // Redirect the discussion type
     if ($node->getType() == 'discussion') {
         $user = $this->currentUser->id();
         $participants = array_column($node->field_participants->getValue(), 'target_id');
         // If it is a private discussion & the user is not a participant, block access.
         if ($node->field_private->value && !in_array($user, $participants)) {
             //$url = Url::fromRoute('entity.node.ahs_discuss', ['node' => $node->id()]);
             //return new RedirectResponse($url->toString());
             drupal_set_message(t('Sorry, this discussion is private and you are not listed as a participant.'), 'warning');
             return array();
         } else {
             return \Drupal::service('entity.form_builder')->getForm($node, 'ahs_discuss');
         }
     } else {
         return parent::view($node, $view_mode, $langcode);
     }
 }
예제 #7
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);
 }
예제 #8
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 buildRow(EntityInterface $field_storage)
 {
     if ($field_storage->isLocked()) {
         $row['class'] = array('menu-disabled');
         $row['data']['id'] = $this->t('@field_name (Locked)', array('@field_name' => $field_storage->getName()));
     } else {
         $row['data']['id'] = $field_storage->getName();
     }
     $field_type = $this->fieldTypes[$field_storage->getType()];
     $row['data']['type'] = $this->t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
     $usage = array();
     foreach ($field_storage->getBundles() as $bundle) {
         $entity_type_id = $field_storage->getTargetEntityTypeId();
         if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
             $usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
         } else {
             $usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
         }
     }
     $usage_escaped = '';
     $separator = '';
     foreach ($usage as $usage_item) {
         $usage_escaped .= $separator . SafeMarkup::escape($usage_item);
         $separator = ', ';
     }
     $row['data']['usage'] = SafeMarkup::set($usage_escaped);
     return $row;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $field_storage)
 {
     if ($field_storage->isLocked()) {
         $row['class'] = array('menu-disabled');
         $row['data']['id'] = $this->t('@field_name (Locked)', array('@field_name' => $field_storage->getName()));
     } else {
         $row['data']['id'] = $field_storage->getName();
     }
     $field_type = $this->fieldTypes[$field_storage->getType()];
     $row['data']['type'] = $this->t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
     $usage = array();
     foreach ($field_storage->getBundles() as $bundle) {
         $entity_type_id = $field_storage->getTargetEntityTypeId();
         if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
             $usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
         } else {
             $usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
         }
     }
     $row['data']['usage']['data'] = ['#theme' => 'item_list', '#items' => $usage, '#context' => ['list_style' => 'comma-list']];
     return $row;
 }