本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::getEntityTypeId方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::getEntityTypeId方法的具体用法?PHP EntityInterface::getEntityTypeId怎么用?PHP EntityInterface::getEntityTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::getEntityTypeId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
示例2: invoke
/**
* Invokes the implementation.
*/
public function invoke(EntityInterface $entity)
{
if ($entity->getEntityTypeId() == 'payment_method_configuration') {
$manager = $this->paymentMethodManager;
} elseif ($entity->getEntityTypeId() == 'payment_status') {
$manager = $this->paymentStatusManager;
}
if (isset($manager) && $manager instanceof CachedDiscoveryInterface) {
$manager->clearCachedDefinitions();
}
}
示例3: getTranslationAccess
/**
* {@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");
}
示例4: assertFieldValues
/**
* 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)));
}
}
示例5: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $entity_clone_handler */
$entity_clone_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone');
if ($this->entityTypeManager->hasHandler($this->entityTypeDefinition->id(), 'entity_clone_form')) {
$entity_clone_form_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone_form');
}
$properties = [];
if (isset($entity_clone_form_handler) && $entity_clone_form_handler) {
$properties = $entity_clone_form_handler->getNewValues($form_state);
}
$cloned_entity = $entity_clone_handler->cloneEntity($this->entity, $this->entity->createDuplicate(), $properties);
drupal_set_message($this->stringTranslationManager->translate('The entity <em>@entity (@entity_id)</em> of type <em>@type</em> was cloned', [
'@entity' => $this->entity->label(),
'@entity_id' => $this->entity->id(),
'@type' => $this->entity->getEntityTypeId(),
]));
if ($cloned_entity && $cloned_entity->hasLinkTemplate('canonical')) {
$form_state->setRedirect($cloned_entity->toUrl()
->getRouteName(), $cloned_entity->toUrl()->getRouteParameters());
}
$form_state->setRedirect('<front>');
}
示例6: access
/**
* {@inheritdoc}
*/
public function access(EntityInterface $entity, $operation, $langcode = LanguageInterface::LANGCODE_DEFAULT, AccountInterface $account = NULL, $return_as_object = FALSE)
{
$account = $this->prepareUser($account);
if (($return = $this->getCache($entity->uuid(), $operation, $langcode, $account)) !== NULL) {
// Cache hit, no work necessary.
return $return_as_object ? $return : $return->isAllowed();
}
// Invoke hook_entity_access() and hook_ENTITY_TYPE_access(). Hook results
// take precedence over overridden implementations of
// EntityAccessControlHandler::checkAccess(). Entities that have checks that
// need to be done before the hook is invoked should do so by overriding
// this method.
// We grant access to the entity if both of these conditions are met:
// - No modules say to deny access.
// - At least one module says to grant access.
$access = array_merge($this->moduleHandler()->invokeAll('entity_access', array($entity, $operation, $account, $langcode)), $this->moduleHandler()->invokeAll($entity->getEntityTypeId() . '_access', array($entity, $operation, $account, $langcode)));
$return = $this->processAccessHookResults($access);
// Also execute the default access check except when the access result is
// already forbidden, as in that case, it can not be anything else.
if (!$return->isForbidden()) {
$return = $return->orIf($this->checkAccess($entity, $operation, $langcode, $account));
}
$result = $this->setCache($return, $entity->uuid(), $operation, $langcode, $account);
return $return_as_object ? $result : $result->isAllowed();
}
示例7: formElement
/**
* {@inheritdoc}
*/
public function formElement(EntityInterface $entity) {
$form = [];
if ($this->entityTypeManager->getDefinition($entity->getEntityTypeId())->getKey('label')) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->translationManager->translate('New Label'),
'#maxlength' => 255,
'#required' => TRUE,
);
}
$form['id'] = array(
'#type' => 'machine_name',
'#title' => $this->translationManager->translate('New Id'),
'#maxlength' => 255,
'#required' => TRUE,
);
// If entity must have a prefix
// (e.g. entity_form_mode, entity_view_mode, ...).
if (method_exists($entity, 'getTargetType')) {
$form['id']['#field_prefix'] = $entity->getTargetType() . '.';
}
if (method_exists($entity, 'load')) {
$form['id']['#machine_name'] = [
'exists' => get_class($entity) . '::load',
];
}
return $form;
}
示例8: checkAccess
/**
* {@inheritdoc}
*/
public function checkAccess(EntityInterface $entity, Route $route, AccountInterface $account, $operation, $graph_name)
{
if (!$entity) {
return FALSE;
}
// For now, we only have the view operation but this is not the only
// operation so we will check anyway.
$map = ['view' => 'view all graphs'];
$entity_type_id = $entity->getEntityTypeId();
$type_map = ['view' => "view {$entity_type_id} {$graph_name} graph"];
// If the operation is not supported, do not allow access.
if (!isset($map[$operation]) || !isset($type_map[$operation])) {
return FALSE;
}
// @todo: This probably needs to be cached manually creating a cid.
// @see: \Drupal\node\Access\NodeRevisionAccessCheck::checkAccess().
// @todo: This needs also to check cache for cached permission.
// @see: \Drupal\Core\Entity\EntityAccessControlHandler::access().
$has_permission = $account->hasPermission($map[$operation]) || $account->hasPermission($type_map[$operation]);
$access = $has_permission ? AccessResult::allowed() : AccessResult::neutral();
$arguments = [$entity, $operation, $account, $graph_name];
$access_array = array_merge([$access], $this->moduleHandler->invokeAll('entity_graph_access', $arguments), $this->moduleHandler->invokeAll($entity_type_id . '_graph_access', $arguments));
$return = $this->processAccessHookResults($access_array);
return $return->isAllowed();
}
示例9: 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;
}
示例10: getForm
/**
* {@inheritdoc}
*/
public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = array())
{
$form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation);
$form_object->setEntity($entity);
$form_state = (new FormState())->setFormState($form_state_additions);
return $this->formBuilder->buildForm($form_object, $form_state);
}
示例11: doEvaluate
/**
* 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;
}
示例12: alterBuild
/**
* {@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()]];
}
}
示例13: getForm
/**
* {@inheritdoc}
*/
public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array())
{
$form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation);
$form_object->setEntity($entity);
$form_state['build_info']['callback_object'] = $form_object;
$form_state['build_info']['base_form_id'] = $form_object->getBaseFormID();
$form_state['build_info'] += array('args' => array());
return $this->formBuilder->buildForm($form_object, $form_state);
}
示例14: init
/**
* Initialize the form state and the entity before the first form build.
*/
protected function init(FormStateInterface $form_state)
{
// Flag that this form has been initialized.
$form_state->set('entity_form_initialized', TRUE);
// Prepare the entity to be presented in the entity form.
$this->prepareEntity();
// Invoke the prepare form hooks.
$this->prepareInvokeAll('entity_prepare_form', $form_state);
$this->prepareInvokeAll($this->entity->getEntityTypeId() . '_prepare_form', $form_state);
}
示例15: create
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;
}