/** * {@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) { /** @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(); } }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($entity->getOwnerId() == $account->id()) { return AccessResult::allowedIfHasPermission($account, $operation . ' own ' . $entity->bundle() . ' entity'); } return AccessResult::allowedIfHasPermission($account, $operation . ' any ' . $entity->bundle() . ' entity'); }
/** * @todo. */ public function check(EntityInterface $entity) { global $user; if (!empty($entity) && (user_access('administer content') || user_access('update any fullcalendar event') || user_access('edit any ' . $entity->bundle() . ' content') || user_access('edit own ' . $entity->bundle() . ' content') && $entity->uid == $user->uid)) { return TRUE; } return FALSE; }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { switch ($operation) { case 'view': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_activity entities', 'view any crm_core_activity entity', 'view any crm_core_activity entity of bundle ' . $entity->bundle()], 'OR'); case 'update': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_activity entities', 'edit any crm_core_activity entity', 'edit any crm_core_activity entity of bundle ' . $entity->bundle()], 'OR'); case 'delete': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_activity entities', 'delete any crm_core_activity entity', 'delete any crm_core_activity entity of bundle ' . $entity->bundle()], 'OR'); } }
/** * {@inheritdoc} */ public function getFormId() { $form_id = $this->entity->getEntityTypeId(); if ($this->entity->getEntityType()->hasKey('bundle')) { $form_id = $this->entity->bundle() . '_' . $form_id; } if ($this->operation != 'default') { $form_id = $form_id . '_' . $this->operation; } return $form_id . '_form'; }
/** * {@inheritdoc} */ public function getFormId() { $entity_type = $this->entity->getEntityTypeId(); $bundle = $this->entity->bundle(); $form_id = $entity_type; if ($bundle != $entity_type) { $form_id = $bundle . '_' . $form_id; } if ($this->operation != 'default') { $form_id = $form_id . '_' . $this->operation; } return $form_id . '_form'; }
/** * Form constructor. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param \Drupal\Core\Entity\EntityInterface $node * The node being previews * * @return array * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $node = NULL) { $view_mode = $node->preview_view_mode; $query_options = $node->isNew() ? array('query' => array('uuid' => $node->uuid())) : array(); $form['backlink'] = array('#type' => 'link', '#title' => $this->t('Back to content editing'), '#url' => $node->isNew() ? Url::fromRoute('node.add', ['node_type' => $node->bundle()]) : $node->urlInfo('edit-form'), '#options' => array('attributes' => array('class' => array('node-preview-backlink'))) + $query_options); $view_mode_options = $this->entityManager->getViewModeOptionsByBundle('node', $node->bundle()); // Unset view modes that are not used in the front end. unset($view_mode_options['rss']); unset($view_mode_options['search_index']); $form['uuid'] = array('#type' => 'value', '#value' => $node->uuid()); $form['view_mode'] = array('#type' => 'select', '#title' => $this->t('View mode'), '#options' => $view_mode_options, '#default_value' => $view_mode, '#attributes' => array('data-drupal-autosubmit' => TRUE)); $form['submit'] = array('#type' => 'submit', '#value' => $this->t('Switch'), '#attributes' => array('class' => array('js-hide'))); return $form; }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': return $account->hasPermission('access content'); break; case 'update': return $account->hasPermission("edit terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'); break; case 'delete': return $account->hasPermission("delete terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'); break; } }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { switch ($operation) { case 'view': return AccessResult::allowedIfHasPermission($account, 'access content'); case 'update': return AccessResult::allowedIfHasPermissions($account, ["edit terms in {$entity->bundle()}", 'administer taxonomy'], 'OR'); case 'delete': return AccessResult::allowedIfHasPermissions($account, ["delete terms in {$entity->bundle()}", 'administer taxonomy'], 'OR'); default: // No opinion. return AccessResult::neutral(); } }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { switch ($operation) { case 'view': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_contact entities', 'view any crm_core_contact entity', 'view any crm_core_contact entity of bundle ' . $entity->bundle()], 'OR'); case 'update': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_contact entities', 'edit any crm_core_contact entity', 'edit any crm_core_contact entity of bundle ' . $entity->bundle()], 'OR'); case 'delete': return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_contact entities', 'delete any crm_core_contact entity', 'delete any crm_core_contact entity of bundle ' . $entity->bundle()], 'OR'); case 'revert': // @todo: more fine grained will be adjusting dynamic permission // generation for reverting bundles of contact. return AccessResult::allowedIfHasPermissions($account, ['administer crm_core_contact entities', 'revert contact record'], 'OR'); } }
function __construct(EntityInterface $entity) { $this->queue = new \Celery('localhost', 'guest', 'guest', '/'); $this->id = $entity->getRevisionId(); $this->ref_id = $entity->nid->value; $this->name = $entity->getTitle(); $this->type = $entity->bundle(); // Host Definition $this->host_def_vars = $this->getHostDefinition($entity); $this->host_def_vars['ran_name'] = $this->name; $this->host_def_type = $this->host_def_vars['_system_type']; unset($this->host_def_vars['_system_type']); // Host Configuration $this->host_conf_vars = $this->getHostConfiguration($entity); $this->host_conf_types = $this->host_conf_vars['_roles']; unset($this->host_conf_vars['_roles']); // Host Description $this->description = 'Generated by Rán.'; $desc = $entity->getFields()['field_ran__description']->getString(); if (isset($this->vars['_description'])) { $this->description = $this->vars['_description']; unset($this->vars['_description']); } $this->org = 'root'; $this->project = 'default'; $this->extra_vars = json_encode(array('ran_name' => $this->name, 'ran_desc' => $this->description, 'ran_type' => $this->type, 'ran_def_type' => $this->host_def_type, 'ran_def_vars' => $this->host_def_vars, 'ran_conf_types' => $this->host_conf_types, 'ran_conf_vars' => $this->host_conf_vars), JSON_UNESCAPED_UNICODE); }
/** * {@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} */ public function isModeratedEntity(EntityInterface $entity) { if (!$entity instanceof ContentEntityInterface) { return FALSE; } return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle()); }
/** * Creates an instance wrapping the given entity. * * @param \Drupal\Core\Entity\EntityInterface|null $entity * The entity object to wrap. * * @return static */ public static function createFromEntity(EntityInterface $entity) { $definition = EntityDataDefinition::create()->setEntityTypeId($entity->getEntityTypeId())->setBundles([$entity->bundle()]); $instance = new static($definition); $instance->setValue($entity); return $instance; }
/** * {@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); }
/** * Check if a provided entity is of a specific type and bundle. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check the bundle and type of. * @param string $type * The type to check for. * @param string $bundle * The bundle to check for. * * @return bool * TRUE if the provided entity is of the provided type and bundle. */ protected function doEvaluate(EntityInterface $entity, $type, $bundle) { $entity_type = $entity->getEntityTypeId(); $entity_bundle = $entity->bundle(); // Check to see whether the entity's bundle and type match the specified // values. return $entity_bundle == $bundle && $entity_type == $type; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /* @var $entity \Drupal\commerce_store\Entity\Store */ $store_type = StoreType::load($entity->bundle()); $row['name']['data'] = ['#type' => 'link', '#title' => $entity->label()] + $entity->urlInfo()->toRenderArray(); $row['type'] = $store_type->label(); return $row + parent::buildRow($entity); }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($shortcut_set = $this->shortcutSetStorage->load($entity->bundle())) { return shortcut_set_edit_access($shortcut_set, $account); } // @todo Fix this bizarre code: how can a shortcut exist without a shortcut // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903. return AccessResult::neutral()->addCacheableDependency($entity); }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\conference_sessions\Entity\RoomTypeInterface $entity */ $product_type = RoomType::load($entity->bundle()); $row['title']['data'] = ['#type' => 'link', '#title' => $entity->label()] + $entity->toUrl()->toRenderArray(); $row['type'] = $product_type->label(); $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished'); return $row + parent::buildRow($entity); }
public function create(EntityInterface $entity) { if (!isset($entity->xmlsitemap)) { $entity->xmlsitemap = array(); if ($entity->id() && ($link = $this->load($entity->getEntityTypeId(), $entity->id()))) { $entity->xmlsitemap = $link; } } $settings = xmlsitemap_link_bundle_load($entity->getEntityTypeId(), $entity->bundle()); $uri = $entity->url(); $entity->xmlsitemap += array('type' => $entity->getEntityTypeId(), 'id' => (string) $entity->id(), 'subtype' => $entity->bundle(), 'status' => $settings['status'], 'status_default' => $settings['status'], 'status_override' => 0, 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, 'changefreq' => isset($settings['changefreq']) ? $settings['changefreq'] : 0); $url = $entity->url(); // The following values must always be checked because they are volatile. $entity->xmlsitemap['loc'] = $uri; $entity->xmlsitemap['access'] = isset($url) && $entity->access('view', $this->anonymousUser); $language = $entity->language(); $entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED; return $entity->xmlsitemap; }
/** * Converts role names into og roles by adding the appropriate prefix. * * This function does not test if the entity is a group. It merely serves as * a name conversion method. * * @param array $roles * An array of roles to convert names. * @param \Drupal\Core\Entity\EntityInterface $group * The group entity. * * @return array * An array with the converted names. */ protected function convertOgRoleNamesToIds(array $roles, EntityInterface $group) { $role_prefix = $group->getEntityTypeId() . '-' . $group->bundle() . '-'; foreach ($roles as $key => $role) { // What is called a "collection owner" or a "solution owner" in Joinup, is // known as an "administrator" in OG. $role = $role === 'owner' ? 'administrator' : $role; $roles[$key] = $role_prefix . $role; } return $roles; }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { switch ($operation) { case 'view': // Check for status and set 'published' or 'unpublished'. $status = $entity->status->value ? 'published' : 'unpublished'; return AccessResult::allowedIf($account->hasPermission('access content') && $account->hasPermission('view ' . $status . ' terms in ' . $entity->bundle())); default: return parent::checkAccess($entity, $operation, $account); } }
/** * 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) { // Ensure user has access to edit this profile. if (!$profile->access('update')) { return; } $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = "user/" . $profile->getOwnerId() . "/profile/" . $profile->bundle() . "/" . $profile->id(); $this->options['alter']['query'] = \Drupal::destination()->getAsArray(); $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit'); return $text; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /* @var $entity \Drupal\commerce_product\Entity\Product */ $productType = ProductType::load($entity->bundle()); $row['title']['data'] = [ '#type' => 'link', '#title' => $entity->label(), ] + $entity->urlInfo()->toRenderArray(); $row['type'] = $productType->label(); $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished'); return $row + parent::buildRow($entity); }
/** * {@inheritdoc} */ public function getTranslationAccess(EntityInterface $entity, $op) { // @todo Move this logic into a translation access controller checking also // the translation language and the given account. $entity_type = $entity->getEntityType(); $translate_permission = TRUE; // If no permission granularity is defined this entity type does not need an // explicit translate permission. $current_user = \Drupal::currentUser(); if (!$current_user->hasPermission('translate any entity') && ($permission_granularity = $entity_type->getPermissionGranularity())) { $translate_permission = $current_user->hasPermission($permission_granularity == 'bundle' ? "translate {$entity->bundle()} {$entity->getEntityTypeId()}" : "translate {$entity->getEntityTypeId()}"); } return $translate_permission && $current_user->hasPermission("{$op} content translations"); }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { /** @var ScheduledUpdate $entity */ if ($operation == 'view') { return AccessResult::allowedIfHasPermission($account, 'view scheduled update entities'); } $type_id = $entity->bundle(); if ($entity->getOwnerId() == $account->id()) { // If owner that needs either own or any permission, not both. return AccessResult::allowedIfHasPermissions($account, ["{$operation} any {$type_id} scheduled updates", "{$operation} own {$type_id} scheduled updates"], 'OR'); } else { return AccessResult::allowedIfHasPermission($account, "{$operation} any {$type_id} scheduled updates"); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // The revision timestamp will be updated when the revision is saved. Keep // the original one for the confirmation message. $this->revision = $this->prepareRevision($this->revision); if ($this->revision instanceof RevisionLogInterface) { $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)])); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => $this->getBundleLabel($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); } else { drupal_set_message(t('@type %title has been reverted', ['@type' => $this->getBundleLabel($this->revision), '%title' => $this->revision->label()])); } $this->revision->save(); $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); $form_state->setRedirect("entity.{$this->revision->getEntityTypeId()}.version_history", [$this->revision->getEntityTypeId() => $this->revision->id()]); }
/** * {@inheritdoc} */ protected function checkAccess(EntityInterface $feed, $operation, $langcode, AccountInterface $account) { if (!in_array($operation, array('view', 'create', 'update', 'delete', 'import', 'clear', 'unlock'))) { // If $operation is not one of the supported actions, we return access // denied. return FALSE; } if ($operation === 'unlock') { // If there is no need to unlock the feed, then the user does not have // access. if ($feed->progressImporting() == StateInterface::BATCH_COMPLETE && $feed->progressClearing() == StateInterface::BATCH_COMPLETE) { return FALSE; } } return $account->hasPermission('administer feeds') || $account->hasPermission("{$operation} {$feed->bundle()} feeds"); }
/** * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $font) { $provider = fontyourface_provider_load($font->bundle()); $form_state['fontyourface']['provider'] = $provider; // Add any form fields that don't map to entity fields here. /* $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $term->name, '#maxlength' => 255, '#required' => TRUE, '#weight' => -5, ); $form['description'] = array( '#type' => 'text_format', '#title' => t('Description'), '#default_value' => $term->description, '#format' => $term->format, '#weight' => 0, ); $language_configuration = module_invoke('language', 'get_default_configuration', 'taxonomy_term', $vocabulary->id()); $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Language'), '#languages' => LANGUAGE_ALL, '#default_value' => $term->langcode, '#access' => !is_null($language_configuration['language_show']) && $language_configuration['language_show'], ); $form['relations'] = array( '#type' => 'details', '#title' => t('Relations'), '#collapsed' => ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE), '#weight' => 10, ); */ $form['pid'] = array('#type' => 'value', '#value' => $provider->id()); $form['fid'] = array('#type' => 'value', '#value' => $font->fid); if (empty($font->fid)) { $form_state['redirect'] = current_path(); } // if return parent::form($form, $form_state, $font); }