本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::bundle方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::bundle方法的具体用法?PHP EntityInterface::bundle怎么用?PHP EntityInterface::bundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::bundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAccess
/**
* {@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');
}
示例2: checkAccess
/**
* {@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();
}
}
示例3: check
/**
* @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;
}
示例4: checkAccess
/**
* {@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');
}
}
示例5: getFormId
/**
* {@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';
}
示例6: getFormId
/**
* {@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';
}
示例7: buildForm
/**
* 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;
}
示例8: checkAccess
/**
* {@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;
}
}
示例9: checkAccess
/**
* {@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();
}
}
示例10: checkAccess
/**
* {@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');
}
}
示例11: unset
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);
}
示例12: save
/**
* {@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();
}
}
示例13: checkAccess
/**
* {@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();
}
}
示例14: isModeratedEntity
/**
* {@inheritdoc}
*/
public function isModeratedEntity(EntityInterface $entity)
{
if (!$entity instanceof ContentEntityInterface) {
return FALSE;
}
return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle());
}
示例15: createFromEntity
/**
* 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;
}