本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeInterface::getBundleEntityType方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeInterface::getBundleEntityType方法的具体用法?PHP EntityTypeInterface::getBundleEntityType怎么用?PHP EntityTypeInterface::getBundleEntityType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityTypeInterface
的用法示例。
在下文中一共展示了EntityTypeInterface::getBundleEntityType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isModeratableBundle
/**
* {@inheritdoc}
*/
public function isModeratableBundle(EntityTypeInterface $entity_type, $bundle)
{
if ($bundle_entity = $this->loadBundleEntity($entity_type->getBundleEntityType(), $bundle)) {
return $bundle_entity->getThirdPartySetting('workbench_moderation', 'enabled', FALSE);
}
return FALSE;
}
示例2: shouldModerateEntitiesOfBundle
/**
* {@inheritdoc}
*/
public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, $bundle)
{
if ($bundle_entity = $this->loadBundleEntity($entity_type->getBundleEntityType(), $bundle)) {
return $bundle_entity->getThirdPartySetting('content_moderation', 'enabled', FALSE);
}
return FALSE;
}
示例3: getItemLabel
/**
* Returns the label for items being created, updated, or deleted.
*
* @return string
* The item label.
*/
public function getItemLabel()
{
if (!$this->entityType->getKey('bundle')) {
return $this->entityTypeLabel();
}
$storage = $this->entityManager->getStorage($this->entityType->getBundleEntityType());
return $storage->load($this->configuration['values'][$this->entityType->getKey('bundle')])->label();
}
示例4: calculateDependencies
/**
* {@inheritdoc}
*/
public function calculateDependencies()
{
$dependencies = parent::calculateDependencies();
$bundle_entity_type = $this->entityType->getBundleEntityType();
$bundle_entity_storage = $this->entityManager->getStorage($bundle_entity_type);
foreach (array_keys($this->value) as $bundle) {
if ($bundle_entity = $bundle_entity_storage->load($bundle)) {
$dependencies[$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
}
}
return $dependencies;
}
示例5: getEntityBundleLabel
/**
* Provides the bundle label with a fallback when not defined.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type we are looking the bundle label for.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The entity bundle label or a fallback label.
*/
protected function getEntityBundleLabel($entity_type)
{
if ($label = $entity_type->getBundleLabel()) {
return $this->t('@label', ['@label' => $label]);
}
$fallback = $entity_type->getLabel();
if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
// This is a better fallback.
$fallback = $this->entityManager->getDefinition($bundle_entity_type)->getLabel();
}
return $this->t('@label bundle', ['@label' => $fallback]);
}
示例6: testToUrlLinkTemplateAddForm
/**
* Tests the toUrl() method with the 'revision' link template.
*
* @param bool $has_bundle_key
* Whether or not the mock entity type should have a bundle key.
* @param string|null $bundle_entity_type
* The ID of the bundle entity type of the mock entity type, or NULL if the
* mock entity type should not have a bundle entity type.
* @param string $bundle_key
* The bundle key of the mock entity type or FALSE if the entity type should
* not have a bundle key.
* @param array $expected_route_parameters
* The expected route parameters of the generated URL.
*
* @dataProvider providerTestToUrlLinkTemplateAddForm
*
* @covers ::toUrl
* @covers ::linkTemplates
* @covers ::urlRouteParameters
*/
public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters)
{
$values = ['id' => $this->entityId, 'langcode' => $this->langcode];
$entity = $this->getEntity(Entity::class, $values);
$this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
$this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
$this->entityType->getKey('bundle')->willReturn($bundle_key);
$link_template = 'add-form';
$this->registerLinkTemplate($link_template);
/** @var \Drupal\Core\Url $url */
$url = $entity->toUrl($link_template);
$this->assertUrl('entity.test_entity.add_form', $expected_route_parameters, $entity, FALSE, $url);
}
示例7: baseFieldDefinitions
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
{
$fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Custom entity ID'))->setDescription(t('The custom entity ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The custom entity UUID.'))->setReadOnly(TRUE);
$fields['revision_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The revision ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')->setLabel(t('Language'))->setDescription(t('The custom entity language code.'))->setTranslatable(TRUE)->setRevisionable(TRUE)->setDisplayOptions('view', array('type' => 'hidden'))->setDisplayOptions('form', array('type' => 'language_select', 'weight' => 2));
$fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Administrative Title'))->setDescription(t('A brief description of this @entity_label entry.', ['@entity_label' => $entity_type->getLabel()]))->setRevisionable(TRUE)->setTranslatable(TRUE)->setRequired(TRUE)->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Authored by'))->setDescription(t('The username of the entity author.'))->setRevisionable(TRUE)->setSetting('target_type', 'user')->setDefaultValueCallback('Drupal\\content_entity_base\\Entity\\EntityBase::getCurrentUserId')->setTranslatable(TRUE)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'author', 'weight' => 0))->setDisplayOptions('form', array('type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => array('match_operator' => 'CONTAINS', 'size' => '60', 'placeholder' => '')))->setDisplayConfigurable('form', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')->setLabel(t('Publishing status'))->setDescription(t('A boolean indicating whether the node is published.'))->setRevisionable(TRUE)->setTranslatable(TRUE)->setDefaultValue(TRUE);
$fields['type'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Entity type (Bundle)'))->setDescription(t('The entity type.'))->setSetting('target_type', $entity_type->getBundleEntityType());
$fields['revision_log'] = BaseFieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The time that the entity was created.'))->setTranslatable(TRUE)->setRevisionable(TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the custom entity was last edited.'))->setTranslatable(TRUE)->setRevisionable(TRUE);
$fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')->setLabel(t('Revision translation affected'))->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))->setReadOnly(TRUE)->setRevisionable(TRUE)->setTranslatable(TRUE);
return $fields;
}
示例8: getSettingsFormRoute
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type)
{
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route->setDefaults(['_form' => 'Drupal\\drupalbristol_sponsors\\Form\\SponsorEntitySettingsForm', '_title' => "{$entity_type->getLabel()} settings"])->setRequirement('_permission', $entity_type->getAdminPermission())->setOption('_admin_route', TRUE);
return $route;
}
}
示例9: getAddFormRoute
/**
* Gets the add-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getAddFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('add-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('add-form'));
// Use the add form handler, if available, otherwise default.
$operation = 'default';
if ($entity_type->getFormClass('add')) {
$operation = 'add';
}
$route->setDefaults(['_entity_form' => "{$entity_type_id}.{$operation}", 'entity_type_id' => $entity_type_id]);
// If the entity has bundles, we can provide a bundle-specific title
// and access requirements.
$expected_parameter = $entity_type->getBundleEntityType() ?: $entity_type->getKey('bundle');
// @todo: We have to check if a route contains a bundle in its path as
// test entities have inconsistent usage of "add-form" link templates.
// Fix it in https://www.drupal.org/node/2699959.
if (($bundle_key = $entity_type->getKey('bundle')) && strpos($route->getPath(), '{' . $expected_parameter . '}') !== FALSE) {
$route->setDefault('_title_callback', EntityController::class . '::addBundleTitle');
// If the bundles are entities themselves, we can add parameter
// information to the route options.
if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
$bundle_entity_type = $this->entityTypeManager->getDefinition($bundle_entity_type_id);
$route->setDefault('bundle_parameter', $bundle_entity_type_id)->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}');
// Entity types with serial IDs can specify this in their route
// requirements, improving the matching process.
if ($this->getEntityTypeIdKeyType($bundle_entity_type) === 'integer') {
$route->setRequirement($entity_type_id, '\\d+');
}
$bundle_entity_parameter = ['type' => 'entity:' . $bundle_entity_type_id];
if ($bundle_entity_type instanceof ConfigEntityTypeInterface) {
// The add page might be displayed on an admin path. Even then, we
// need to load configuration overrides so that, for example, the
// bundle label gets translated correctly.
// @see \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter
$bundle_entity_parameter['with_config_overrides'] = TRUE;
}
$route->setOption('parameters', [$bundle_entity_type_id => $bundle_entity_parameter]);
} else {
// If the bundles are not entities, the bundle key is used as the
// route parameter name directly.
$route->setDefault('bundle_parameter', $bundle_key)->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_key . '}');
}
} else {
$route->setDefault('_title_callback', EntityController::class . '::addTitle')->setRequirement('_entity_create_access', $entity_type_id);
}
return $route;
}
}
示例10: getRouteBundleParameter
/**
* Gets the route parameter that should be used for Field UI routes.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The actual entity type, not the bundle (e.g. the content entity type).
* @param string $bundle
* The bundle name.
*
* @return array
* An array that can be used a route parameter.
*/
public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle)
{
return array($entity_type->getBundleEntityType() => $bundle);
}
示例11: getRouteBundleParameter
/**
* Gets the route parameter that should be used for Field UI routes.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The actual entity type, not the bundle (e.g. the content entity type).
* @param string $bundle
* The bundle name.
*
* @return array
* An array that can be used a route parameter.
*/
public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle)
{
$bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle';
return array($bundle_parameter_key => $bundle);
}
示例12: getBundleLabel
/**
* Returns the bundle label for a given entity type.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return string
* The bundle label.
*/
protected function getBundleLabel(EntityTypeInterface $entity_type)
{
if ($entity_type->getBundleLabel()) {
return $entity_type->getBundleLabel();
}
if ($entity_type->getBundleEntityType()) {
return \Drupal::entityTypeManager()->getDefinition($entity_type->getBundleEntityType())->getLabel();
}
return $this->t('@label type', ['@label' => $entity_type->getLabel()]);
}
示例13: baseFieldDefinitions
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
{
$fields = [];
if ($entity_type->hasKey('id')) {
$fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
}
if ($entity_type->hasKey('uuid')) {
$fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')->setLabel(new TranslatableMarkup('UUID'))->setReadOnly(TRUE);
}
if ($entity_type->hasKey('revision')) {
$fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('Revision ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
}
if ($entity_type->hasKey('langcode')) {
$fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')->setLabel(new TranslatableMarkup('Language'))->setDisplayOptions('view', ['type' => 'hidden'])->setDisplayOptions('form', ['type' => 'language_select', 'weight' => 2]);
if ($entity_type->isRevisionable()) {
$fields[$entity_type->getKey('langcode')]->setRevisionable(TRUE);
}
if ($entity_type->isTranslatable()) {
$fields[$entity_type->getKey('langcode')]->setTranslatable(TRUE);
}
}
if ($entity_type->hasKey('bundle')) {
if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
$fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference')->setLabel($entity_type->getBundleLabel())->setSetting('target_type', $bundle_entity_type_id)->setRequired(TRUE)->setReadOnly(TRUE);
} else {
$fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')->setLabel($entity_type->getBundleLabel())->setRequired(TRUE)->setReadOnly(TRUE);
}
}
return $fields;
}