Example #1
0
 /**
  * Returns the bundle label for the entity being processed.
  *
  * @return string
  *   The bundle label.
  */
 protected function bundleLabel()
 {
     if ($label = $this->entityType->getBundleLabel()) {
         return $label;
     }
     return $this->t('Bundle');
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function summary()
 {
     if (count($this->configuration['bundles']) > 1) {
         $bundles = $this->configuration['bundles'];
         $last = array_pop($bundles);
         $bundles = implode(', ', $bundles);
         return $this->t('@bundle_type is @bundles or @last', array('@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundles' => $bundles, '@last' => $last));
     }
     $bundle = reset($this->configuration['bundles']);
     return $this->t('@bundle_type is @bundle', array('@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundle' => $bundle));
 }
Example #3
0
 /**
  * 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]);
 }
 /**
  * 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()]);
 }
Example #5
0
 /**
  * {@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;
 }