getSingularLabel example

// Get entity type ID from the route because ::buildForm has not yet been     // called.     $entity_type_id = $this->getRouteMatch()->getParameter('entity_type_id');
    return $entity_type_id . '_delete_multiple_confirm_form';
  }

  /** * {@inheritdoc} */
  public function getQuestion() {
    return $this->formatPlural(count($this->selection), 'Are you sure you want to delete this @item?', 'Are you sure you want to delete these @items?', [
      '@item' => $this->entityType->getSingularLabel(),
      '@items' => $this->entityType->getPluralLabel(),
    ]);
  }

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    if ($this->entityType->hasLinkTemplate('collection')) {
      return new Url('entity.' . $this->entityTypeId . '.collection');
    }
    
public function getConfirmText() {
    return $this->t('Remove');
  }

  /** * {@inheritdoc} */
  public function getQuestion() {
    $entity = $this->getEntity();
    $regions = $this->systemRegionList($entity->getTheme(), REGIONS_VISIBLE);
    return $this->t('Are you sure you want to remove the @entity-type %label from the %region region?', [
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
      '%label' => $entity->label(),
      '%region' => $regions[$entity->getRegion()],
    ]);
  }

  /** * {@inheritdoc} */
  public function getDescription() {
    return $this->t('This will remove the block placement. You will need to <a href=":url">place it again</a> in order to undo this action.', [
      ':url' => Url::fromRoute('block.admin_display_theme', ['theme' => $this->getEntity()->getTheme()])->toString(),
    ]);
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->migration = $this->prophesize(MigrationInterface::class);
    $this->storage = $this->prophesize(EntityStorageInterface::class);

    $this->entityType = $this->prophesize(EntityTypeInterface::class);
    $this->entityType->getSingularLabel()->willReturn('foo');
    $this->entityType->getPluralLabel()->willReturn('bar');
    $this->storage->getEntityType()->willReturn($this->entityType->reveal());
    $this->storage->getEntityTypeId()->willReturn('foo');
  }

  /** * Tests that revision destination fails for unrevisionable entities. */
  public function testUnrevisionable() {
    $this->entityType->getKey('id')->willReturn('id');
    $this->entityType->getKey('revision')->willReturn('');
    
/** * {@inheritdoc} */
  public function getQuestion() {
    if ($this->data['config_type'] === 'system.simple') {
      $name = $this->data['config_name'];
      $type = $this->t('simple configuration');
    }
    else {
      $definition = $this->entityTypeManager->getDefinition($this->data['config_type']);
      $name = $this->data['import'][$definition->getKey('id')];
      $type = $definition->getSingularLabel();
    }

    $args = [
      '%name' => $name,
      '@type' => strtolower($type),
    ];
    if ($this->configExists) {
      $question = $this->t('Are you sure you want to update the %name @type?', $args);
    }
    else {
      $question = $this->t('Are you sure you want to create a new %name @type?', $args);
    }

class EntityDisplayModeDeleteForm extends EntityDeleteForm {

  /** * {@inheritdoc} */
  public function getDescription() {
    $entity_type = $this->entity->getEntityType();
    return $this->t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', ['@entity-type' => $entity_type->getSingularLabel()]);
  }

}
$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());
  }

  /** * @covers ::getSingularLabel */
  public function testGetSingularLabelDefault() {
    $entity_type = $this->setUpEntityType(['label' => 'Entity test Singular']);
    $entity_type->setStringTranslation($this->getStringTranslationStub());
    $this->assertEquals('entity test singular', $entity_type->getSingularLabel());
  }

  
// Make sure there is only a single 'Translate' operation for each       // dropbutton.       foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
        $this->assertCount(1, $dropbutton->findAll('xpath', 'li'));
        $this->assertSame('Translate', $dropbutton->getText());
      }

      $entity_type = \Drupal::entityTypeManager()->getDefinition($test_entity->getEntityTypeId());
      $this->drupalGet($base_url . '/translate');

      $title = $test_entity->label() . ' ' . $entity_type->getSingularLabel();
      $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
      $this->assertSession()->responseContains($title);
      $this->assertSession()->responseContains('<th>Language</th>');

      $this->drupalGet($base_url);
      $this->assertSession()->linkExists('Translate test configuration');
    }
  }

  /** * Tests availability of hidden entities in the translation overview. */
->save();

    $entity = EntityTestStringId::create([
      'id' => $id,
      'name' => $value,
    ]);
    /** @var \Symfony\Component\Validator\ConstraintViolationList $violations */
    $violations = $entity->get('name')->validate();

    $message = new FormattableMarkup('A @entity_type with @field_name %value already exists.', [
      '%value' => $value,
      '@entity_type' => $entity->getEntityType()->getSingularLabel(),
      '@field_name' => 'Name',
    ]);

    // Check that the validation has created the appropriate violation.     $this->assertCount(1, $violations);
    $this->assertEquals($message$violations[0]->getMessage());
  }

  /** * Data provider for ::testEntityWithStringIdWithViolation(). * * @return array * An array of test cases. * * @see self::testEntityWithStringIdWithViolation() */
$form['#suffix'] = '</div>' . $form['#suffix'];

    $form['#attributes']['class'] = ['form-edit'];

    if ($view->isLocked()) {
      $form['locked'] = [
        '#type' => 'container',
        '#attributes' => ['class' => ['view-locked', 'messages', 'messages--warning']],
        '#weight' => -10,
        'message' => [
          '#type' => 'break_lock_link',
          '#label' => $view->getEntityType()->getSingularLabel(),
          '#lock' => $view->getLock(),
          '#url' => $view->toUrl('break-lock-form'),
        ],
      ];
    }
    else {
      $form['changed'] = [
        '#type' => 'container',
        '#attributes' => ['class' => ['view-changed', 'messages', 'messages--warning']],
        '#children' => $this->t('You have unsaved changes.'),
        '#weight' => -10,
      ];
abstract protected function isApplicable(EntityTypeInterface $entity_type);

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (empty($this->derivatives)) {
      $definitions = [];
      foreach ($this->getApplicableEntityTypes() as $entity_type_id => $entity_type) {
        $definition = $base_plugin_definition;
        $definition['type'] = $entity_type_id;
        $definition['label'] = sprintf('%s %s', $base_plugin_definition['action_label']$entity_type->getSingularLabel());
        $definitions[$entity_type_id] = $definition;
      }
      $this->derivatives = $definitions;
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

  /** * Gets a list of applicable entity types. * * The list consists of all entity types which match the conditions for the * given deriver. * For example, if the action applies to entities that are publishable, * this method will find all entity types that are publishable. * * @return \Drupal\Core\Entity\EntityTypeInterface[] * The applicable entity types, keyed by entity type ID. */
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);

      if (!$entity_type instanceof ConfigEntityTypeInterface) {
        throw new LogicException("'$entity_type_id' is not a config entity type.");
      }

      // Ensure the current entity type's config prefix is found in the config       // dependencies of the entity being validated.       $pattern = sprintf('/^%s\\.\\w+/', $entity_type->getConfigPrefix());
      if (!preg_grep($pattern$config_dependencies)) {
        $this->context->addViolation($constraint->message, [
          '@entity_type' => $entity->getEntityType()->getSingularLabel(),
          '@dependency_type' => $entity_type->getSingularLabel(),
        ]);
      }
    }
  }

}
protected $targetEntityTypeId;

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state$entity_type_id = NULL) {
    $this->targetEntityTypeId = $entity_type_id;
    $form = parent::buildForm($form$form_state);
    // Change replace_pattern to avoid undesired dots.     $form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
    $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId);
    $form['#title'] = $this->t('Add new @entity-type %label', ['@entity-type' => $definition->getLabel(), '%label' => $this->entityType->getSingularLabel()]);
    return $form;
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    $form_state->setValueForElement($form['id']$this->targetEntityTypeId . '.' . $form_state->getValue('id'));
  }

  
'#default_value' => $is_enabled,
    ];
    $form['#entity_builders']['layout_builder'] = '::entityFormEntityBuild';

    // @todo Expand to work for all view modes in     // https://www.drupal.org/node/2907413.     if ($this->isCanonicalMode($this->entity->getMode())) {
      $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
      $form['layout']['allow_custom'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Allow each @entity to have its layout customized.', [
          '@entity' => $entity_type->getSingularLabel(),
        ]),
        '#default_value' => $this->entity->isOverridable(),
        '#states' => [
          'disabled' => [
            ':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
          'invisible' => [
            ':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
        ],
      ];
      

      ],
    ];

    foreach ($referenced_entities as $delta => $media_item) {
      if ($media_item->access('view')) {
        // @todo Make the view mode configurable in https://www.drupal.org/project/drupal/issues/2971209         $preview = $view_builder->view($media_item, 'media_library');
      }
      else {
        $item_label = $media_item->access('view label') ? $media_item->label() : new FormattableMarkup('@label @id', [
          '@label' => $media_item->getEntityType()->getSingularLabel(),
          '@id' => $media_item->id(),
        ]);
        $preview = [
          '#theme' => 'media_embed_error',
          '#message' => $this->t('You do not have permission to view @item_label.', ['@item_label' => $item_label]),
        ];
      }
      $element['selection'][$delta] = [
        '#theme' => 'media_library_item__widget',
        '#attributes' => [
          'class' => [
            
// Move content at the top.       if ($entity_type == 'node') {
        $table['#weight'] = -10;
      }

      $short_type = str_replace(['entity_', '_mode'], '', $this->entityTypeId);
      $table['#rows']['_add_new'][] = [
        'data' => [
          '#type' => 'link',
          '#url' => Url::fromRoute($short_type == 'view' ? 'entity.entity_view_mode.add_form' : 'entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type]),
          '#title' => $this->t('Add new @entity-type %label', ['@entity-type' => $this->entityTypes[$entity_type]->getLabel(), '%label' => $this->entityType->getSingularLabel()]),
        ],
        'colspan' => count($table['#header']),
      ];
      $build[$entity_type] = $table;
    }
    return $build;
  }

  /** * Filters entities based on their view builder handlers. * * @param $entity_type * The entity type of the entity that needs to be validated. * * @return bool * TRUE if the entity has the correct view builder handler, FALSE if the * entity doesn't have the correct view builder handler. */
Home | Imprint | This part of the site doesn't use cookies.