getCollectionLabel example


    return NULL;
  }

  /** * {@inheritdoc} */
  public function getUnsupportedFeatures(EntityTypeInterface $entity_type) {
    $features = [];
    // Test if entity is publishable.     if (!$entity_type->entityClassImplements(EntityPublishedInterface::class)) {
      $features['publishing'] = $this->t("@entity_type_plural_label do not support publishing statuses. For example, even after transitioning from a published workflow state to an unpublished workflow state they will still be visible to site visitors.", ['@entity_type_plural_label' => $entity_type->getCollectionLabel()]);
    }
    return $features;
  }

  /** * {@inheritdoc} */
  public function getOriginalState(ContentEntityInterface $entity) {
    $state = NULL;
    $workflow_type = $this->getWorkflowForEntity($entity)->getTypePlugin();
    if (!$entity->isNew() && !$this->isFirstTimeModeration($entity)) {
      

  protected function getCollectionRoute(EntityTypeInterface $entity_type) {
    // If the entity type does not provide an admin permission, there is no way     // to control access, so we cannot provide a route in a sensible way.     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass() && ($admin_permission = $entity_type->getAdminPermission())) {
      /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
      $label = $entity_type->getCollectionLabel();

      $route = new Route($entity_type->getLinkTemplate('collection'));
      $route
        ->addDefaults([
          '_entity_list' => $entity_type->id(),
          '_title' => $label->getUntranslatedString(),
          '_title_arguments' => $label->getArguments(),
          '_title_context' => $label->getOption('context'),
        ])
        ->setRequirement('_permission', $admin_permission);

      
$paths["\Drupal\\{$module}\Entity"] = $base_directory . $module . '/src/';
    }
    $namespaces = new \ArrayObject($paths);
    $discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
    $definitions = $discovery->getDefinitions();

    foreach ($definitions as $definition) {
      /** @var \Drupal\Core\Entity\EntityType $definition */

      /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
      $label = $definition->getLabel();
      $collection_label = $definition->getCollectionLabel();

      $label_string = $label->getUntranslatedString();
      $collection_label_string = $collection_label->getUntranslatedString();

      // Keep the first word as it is for nouns that are all capital letters       // (like RDF, URL alias etc.) so we can't run strtolower() for the entire       // string. Special cases may need to be added to this test in the future       // if an acronym is in a different position in the label.       $first_word = strtok($label_string, " ");
      $remaining_string = strtolower(strstr($label_string, " "));
      $this->assertEquals($first_word . $remaining_string$label_string);

      
$data['no_list_builder'] = [NULL, $entity_type2->reveal()];

    $entity_type3 = static::getEntityType($entity_type2);
    $entity_type3->hasListBuilderClass()->willReturn(TRUE);
    $entity_type3->getAdminPermission()->willReturn(FALSE);
    $data['no_admin_permission'] = [NULL, $entity_type3->reveal()];

    $entity_type4 = static::getEntityType($entity_type3);
    $entity_type4->getAdminPermission()->willReturn('administer the entity type');
    $entity_type4->id()->willReturn('the_entity_type_id');
    $entity_type4->getLabel()->willReturn('The entity type');
    $entity_type4->getCollectionLabel()->willReturn(new TranslatableMarkup('Test entities'));
    $entity_type4->getLinkTemplate('collection')->willReturn('/the/collection/link/template');
    $entity_type4->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
    $route = (new Route('/the/collection/link/template'))
      ->setDefaults([
        '_entity_list' => 'the_entity_type_id',
        '_title' => 'Test entities',
        '_title_arguments' => [],
        '_title_context' => '',
      ])
      ->setRequirements([
        '_permission' => 'administer the entity type',
      ]);

  public function validate($value, Constraint $constraint) {
    // The validator should run only if we are in a active workspace context.     if (!$this->workspaceManager->hasActiveWorkspace()) {
      return;
    }

    $target_entity_type_id = $value->getFieldDefinition()->getFieldStorageDefinition()->getSetting('target_type');
    $target_entity_type = $this->entityTypeManager->getDefinition($target_entity_type_id);

    if ($value->hasNewEntity() && !$this->workspaceManager->isEntityTypeSupported($target_entity_type)) {
      $this->context->addViolation($constraint->message, ['%collection_label' => $target_entity_type->getCollectionLabel()]);
    }
  }

}
$entity_type = $this->setUpEntityType(['group_label' => $default_label]);
    $this->assertSame($default_label$entity_type->getGroupLabel());
  }

  /** * @covers ::getCollectionLabel */
  public function testGetCollectionLabel() {
    $translatable_label = new TranslatableMarkup('Entity test collection', [][]$this->getStringTranslationStub());
    $entity_type = $this->setUpEntityType(['label_collection' => $translatable_label]);
    $entity_type->setStringTranslation($this->getStringTranslationStub());
    $this->assertEquals('Entity test collection', $entity_type->getCollectionLabel());
  }

  /** * @covers ::getSingularLabel */
  public function testGetSingularLabel() {
    $translatable_label = new TranslatableMarkup('entity test singular', [][]$this->getStringTranslationStub());
    $entity_type = $this->setUpEntityType(['label_singular' => $translatable_label]);
    $entity_type->setStringTranslation($this->getStringTranslationStub());
    $this->assertEquals('entity test singular', $entity_type->getSingularLabel());
  }

  

  public function permissions() {
    $permissions = [];

    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $entity_displays */
    $entity_displays = $this->entityTypeManager->getStorage('entity_view_display')->loadByProperties(['third_party_settings.layout_builder.allow_custom' => TRUE]);
    foreach ($entity_displays as $entity_display) {
      $entity_type_id = $entity_display->getTargetEntityTypeId();
      $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
      $bundle = $entity_display->getTargetBundle();
      $args = [
        '%entity_type' => $entity_type->getCollectionLabel(),
        '@entity_type_singular' => $entity_type->getSingularLabel(),
        '@entity_type_plural' => $entity_type->getPluralLabel(),
        '%bundle' => $this->bundleInfo->getBundleInfo($entity_type_id)[$bundle]['label'],
      ];
      // These permissions are generated on behalf of $entity_display entity       // display, therefore add this entity display as a config dependency.       $dependencies = [
        $entity_display->getConfigDependencyKey() => [
          $entity_display->getConfigDependencyName(),
        ],
      ];
      
Home | Imprint | This part of the site doesn't use cookies.