本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeInterface::getLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeInterface::getLabel方法的具体用法?PHP EntityTypeInterface::getLabel怎么用?PHP EntityTypeInterface::getLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityTypeInterface
的用法示例。
在下文中一共展示了EntityTypeInterface::getLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: permissionLabels
/**
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_info
*
* @return mixed
*/
protected function permissionLabels(EntityTypeInterface $entity_info)
{
$labels = $entity_info->get("permission_labels");
if (!isset($labels['singular'])) {
$labels['singular'] = $entity_info->getLabel();
}
if (!isset($labels['plural'])) {
$labels['plural'] = $entity_info->getLabel();
}
return $labels;
}
示例2: getValueOptions
/**
* Overrides \Drupal\views\Plugin\views\filter\InOperator::getValueOptions().
*/
public function getValueOptions()
{
if (!isset($this->value_options)) {
$types = entity_get_bundles($this->entityTypeId);
$this->value_title = t('@entity types', array('@entity' => $this->entityType->getLabel()));
$options = array();
foreach ($types as $type => $info) {
$options[$type] = $info['label'];
}
asort($options);
$this->value_options = $options;
}
return $this->value_options;
}
示例3: testGetBaseFieldDefinitionsInvalidDefinition
/**
* Tests the getBaseFieldDefinitions() method with an invalid definition.
*
* @covers ::getBaseFieldDefinitions
* @covers ::buildBaseFieldDefinitions
*
* @expectedException \LogicException
*/
public function testGetBaseFieldDefinitionsInvalidDefinition()
{
$this->setUpEntityWithFieldDefinition(FALSE, 'langcode', array('langcode' => 'langcode'));
$this->entityType->isTranslatable()->willReturn(TRUE);
$this->entityType->getLabel()->willReturn('the_label');
$this->entityManager->getBaseFieldDefinitions('test_entity_type');
}
示例4: getViewsData
/**
* {@inheritdoc}
*/
public function getViewsData()
{
$data = [];
// @todo In theory we should use the data table as base table, as this would
// save one pointless join (and one more for every relationship).
// @see https://drupal.org/node/2337509
$base_table = $this->entityType->getBaseTable();
$base_field = $this->entityType->getKey('id');
$data_table = $this->entityType->getDataTable();
$revision_table = $this->entityType->getRevisionTable();
$revision_data_table = $this->entityType->getRevisionDataTable();
$revision_field = $this->entityType->getKey('revision');
// Setup base information of the views data.
$data[$base_table]['table']['entity type'] = $this->entityType->id();
$data[$base_table]['table']['group'] = $this->entityType->getLabel();
$data[$base_table]['table']['base'] = ['field' => $base_field, 'title' => $this->entityType->getLabel()];
if ($label_key = $this->entityType->getKey('label')) {
if ($data_table) {
$data[$base_table]['table']['base']['defaults'] = array('field' => $label_key, 'table' => $data_table);
} else {
$data[$base_table]['table']['base']['defaults'] = array('field' => $label_key);
}
}
// Setup relations to the revisions/property data.
if ($data_table) {
$data[$data_table]['table']['join'][$base_table] = ['left_field' => $base_field, 'field' => $base_field, 'type' => 'INNER'];
$data[$data_table]['table']['entity type'] = $this->entityType->id();
$data[$data_table]['table']['group'] = $this->entityType->getLabel();
}
if ($revision_table) {
$data[$revision_table]['table']['entity type'] = $this->entityType->id();
$data[$revision_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_table]['table']['base'] = array('field' => $revision_field, 'title' => $this->t('@entity_type revisions', array('@entity_type' => $this->entityType->getLabel())));
// Join the revision table to the base table.
$data[$revision_table]['table']['join'][$base_table] = array('left_field' => $revision_field, 'field' => $revision_field, 'type' => 'INNER');
if ($revision_data_table) {
$data[$revision_data_table]['table']['entity type'] = $this->entityType->id();
$data[$revision_data_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_data_table]['table']['join'][$revision_table] = array('left_field' => $revision_field, 'field' => $revision_field, 'type' => 'INNER');
}
}
// Load all typed data definitions of all fields. This should cover each of
// the entity base, revision, data tables.
$field_definitions = $this->entityManager->getBaseFieldDefinitions($this->entityType->id());
if ($table_mapping = $this->storage->getTableMapping()) {
// Iterate over each table we have so far and collect field data for each.
// Based on whether the field is in the field_definitions provided by the
// entity manager.
// @todo We should better just rely on information coming from the entity
// storage.
// @todo https://drupal.org/node/2337511
foreach ($table_mapping->getTableNames() as $table) {
foreach ($table_mapping->getFieldNames($table) as $field_name) {
$this->mapFieldDefinition($table, $field_name, $field_definitions[$field_name], $table_mapping, $data[$table]);
}
}
}
return $data;
}
示例5: collectionRoute
protected function collectionRoute(EntityTypeInterface $entity_type)
{
$route = new Route($entity_type->getLinkTemplate('collection'));
$route->setDefault('_title', $entity_type->getLabel() . ' content');
$route->setDefault('_entity_list', $entity_type->id());
$route->setRequirement('_permission', 'view ' . $entity_type->id() . ' entity');
return $route;
}
示例6: render
/**
* {@inheritdoc}
*
* Builds the entity listing as renderable array for theme_table().
*
* @todo Add a link to add a new item to the #empty text.
*/
public function render()
{
$build = array('#type' => 'table', '#header' => $this->buildHeader(), '#title' => $this->getTitle(), '#rows' => array(), '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())));
foreach ($this->load() as $entity) {
if ($row = $this->buildRow($entity)) {
$build['#rows'][$entity->id()] = $row;
}
}
return $build;
}
示例7: summary
/**
* {@inheritdoc}
*/
public function summary()
{
if (count($this->configuration['bundles']) > 1) {
$bundles = $this->configuration['bundles'];
$last = array_pop($bundles);
$bundles = implode(', ', $bundles);
return $this->t('The @entity_type @bundle_type is @bundles or @last', array('@entity_type' => strtolower($this->bundleOf->getLabel()), '@bundle_type' => strtolower($this->bundleType->getLabel()), '@bundles' => $bundles, '@last' => $last));
}
$bundle = reset($this->configuration['bundles']);
return $this->t('The @entity_type @bundle_type is @bundle', array('@entity_type' => strtolower($this->bundleOf->getLabel()), '@bundle_type' => strtolower($this->bundleType->getLabel()), '@bundle' => $bundle));
}
示例8: 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]);
}
示例9: addEntityLinks
/**
* Sets the entity links in case corresponding link templates exist.
*
* @param array $data
* The views data of the base table.
*/
protected function addEntityLinks(array &$data)
{
$entity_type_id = $this->entityType->id();
$t_arguments = ['@entity_type_label' => $this->entityType->getLabel()];
if ($this->entityType->hasLinkTemplate('canonical')) {
$data['view_' . $entity_type_id] = ['field' => ['title' => $this->t('Link to @entity_type_label', $t_arguments), 'help' => $this->t('Provide a view link to the @entity_type_label.', $t_arguments), 'id' => 'entity_link']];
}
if ($this->entityType->hasLinkTemplate('edit-form')) {
$data['edit_' . $entity_type_id] = ['field' => ['title' => $this->t('Link to edit @entity_type_label', $t_arguments), 'help' => $this->t('Provide an edit link to the @entity_type_label.', $t_arguments), 'id' => 'entity_link_edit']];
}
if ($this->entityType->hasLinkTemplate('delete-form')) {
$data['delete_' . $entity_type_id] = ['field' => ['title' => $this->t('Link to delete @entity_type_label', $t_arguments), 'help' => $this->t('Provide a delete link to the @entity_type_label.', $t_arguments), 'id' => 'entity_link_delete']];
}
}
示例10: render
/**
* {@inheritdoc}
*
* Builds the entity listing as renderable array for table.html.twig.
*
* @todo Add a link to add a new item to the #empty text.
*/
public function render()
{
$build['table'] = array('#type' => 'table', '#header' => $this->buildHeader(), '#title' => $this->getTitle(), '#rows' => array(), '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())), '#cache' => ['contexts' => $this->entityType->getListCacheContexts()]);
foreach ($this->load() as $entity) {
if ($row = $this->buildRow($entity)) {
$build['table']['#rows'][$entity->id()] = $row;
}
}
// Only add the pager if a limit is specified.
if ($this->limit) {
$build['pager'] = array('#type' => 'pager');
}
return $build;
}
示例11: 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}", '_title' => "Add {$entity_type->getLabel()}"])->setRequirement('_entity_create_access', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]])->setOption('_admin_route', TRUE);
return $route;
}
}
示例12: 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;
}
示例13: getEntityCloneRoute
/**
* Gets the entity_clone route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getEntityCloneRoute(EntityTypeInterface $entity_type) {
if ($clone_form = $entity_type->getLinkTemplate('clone-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($clone_form);
$route
->addDefaults([
'_form' => '\Drupal\entity_clone\Form\EntityCloneForm',
'_title' => 'Clone ' . $entity_type->getLabel(),
])
->addRequirements([
'_permission' => 'clone ' . $entity_type->id() . ' entity',
])
->setOption('_entity_clone_entity_type_id', $entity_type_id)
->setOption('_admin_route', TRUE)
->setOption('parameters', [
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
]);
return $route;
}
}
示例14: 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;
}
}
示例15: getViewsData
/**
* {@inheritdoc}
*/
public function getViewsData()
{
$data = [];
$base_table = $this->entityType->getBaseTable();
$base_field = $this->entityType->getKey('id');
$data_table = $this->entityType->getDataTable();
$revision_table = $this->entityType->getRevisionTable();
$revision_data_table = $this->entityType->getRevisionDataTable();
$revision_field = $this->entityType->getKey('revision');
// Setup base information of the views data.
$data[$base_table]['table']['group'] = $this->entityType->getLabel();
$data[$base_table]['table']['provider'] = $this->entityType->getProvider();
$views_base_table = $base_table;
if ($data_table) {
$views_base_table = $data_table;
}
$data[$views_base_table]['table']['base'] = ['field' => $base_field, 'title' => $this->entityType->getLabel(), 'cache_contexts' => $this->entityType->getListCacheContexts()];
$data[$base_table]['table']['entity revision'] = FALSE;
if ($label_key = $this->entityType->getKey('label')) {
if ($data_table) {
$data[$views_base_table]['table']['base']['defaults'] = array('field' => $label_key, 'table' => $data_table);
} else {
$data[$views_base_table]['table']['base']['defaults'] = array('field' => $label_key);
}
}
$data[$base_table]['operations'] = array('field' => array('title' => $this->t('Operations links'), 'help' => $this->t('Provides links to perform entity operations.'), 'id' => 'entity_operations'));
// Setup relations to the revisions/property data.
if ($data_table) {
$data[$base_table]['table']['join'][$data_table] = ['left_field' => $base_field, 'field' => $base_field, 'type' => 'INNER'];
$data[$data_table]['table']['group'] = $this->entityType->getLabel();
$data[$data_table]['table']['provider'] = $this->entityType->getProvider();
$data[$data_table]['table']['entity revision'] = FALSE;
}
if ($revision_table) {
$data[$revision_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_table]['table']['provider'] = $this->entityType->getProvider();
$views_revision_base_table = $revision_table;
if ($revision_data_table) {
$views_revision_base_table = $revision_data_table;
}
$data[$views_revision_base_table]['table']['entity revision'] = TRUE;
$data[$views_revision_base_table]['table']['base'] = array('field' => $revision_field, 'title' => $this->t('@entity_type revisions', array('@entity_type' => $this->entityType->getLabel())));
// Join the revision table to the base table.
$data[$views_revision_base_table]['table']['join'][$views_base_table] = array('left_field' => $revision_field, 'field' => $revision_field, 'type' => 'INNER');
if ($revision_data_table) {
$data[$revision_data_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_data_table]['table']['entity revision'] = TRUE;
$data[$revision_data_table]['table']['join'][$revision_table] = array('left_field' => $revision_field, 'field' => $revision_field, 'type' => 'INNER');
}
}
// Load all typed data definitions of all fields. This should cover each of
// the entity base, revision, data tables.
$field_definitions = $this->entityManager->getBaseFieldDefinitions($this->entityType->id());
if ($table_mapping = $this->storage->getTableMapping()) {
// Iterate over each table we have so far and collect field data for each.
// Based on whether the field is in the field_definitions provided by the
// entity manager.
// @todo We should better just rely on information coming from the entity
// storage.
// @todo https://drupal.org/node/2337511
foreach ($table_mapping->getTableNames() as $table) {
foreach ($table_mapping->getFieldNames($table) as $field_name) {
$this->mapFieldDefinition($table, $field_name, $field_definitions[$field_name], $table_mapping, $data[$table]);
}
}
}
// Add the entity type key to each table generated.
$entity_type_id = $this->entityType->id();
array_walk($data, function (&$table_data) use($entity_type_id) {
$table_data['table']['entity type'] = $entity_type_id;
});
return $data;
}