Commit 9da1866d authored by catch's avatar catch
Browse files

Issue #3232673 by alexpott, longwave, Berdir, andypost:...

Issue #3232673 by alexpott, longwave, Berdir, andypost: \Drupal\Core\Entity\EntityInterface::label() can return a NULL
parent 7e4e5c8d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -231,8 +231,8 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
    $a_weight = isset($a->weight) ? $a->weight : 0;
    $b_weight = isset($b->weight) ? $b->weight : 0;
    if ($a_weight == $b_weight) {
      $a_label = $a->label();
      $b_label = $b->label();
      $a_label = $a->label() ?? '';
      $b_label = $b->label() ?? '';
      return strnatcasecmp($a_label, $b_label);
    }
    return ($a_weight < $b_weight) ? -1 : 1;
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ abstract protected function logger($channel);
  public function getQuestion() {
    return $this->t('Are you sure you want to delete the @entity-type %label?', [
      '@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
      '%label' => $this->getEntity()->label(),
      '%label' => $this->getEntity()->label() ?? $this->getEntity()->id(),
    ]);
  }

@@ -67,7 +67,7 @@ protected function getDeletionMessage() {
    $entity = $this->getEntity();
    return $this->t('The @entity-type %label has been deleted.', [
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
      '%label' => $entity->label(),
      '%label' => $entity->label() ?? $entity->id(),
    ]);
  }

+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public function bundle();
  /**
   * Gets the label of the entity.
   *
   * @return string|null
   * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup|null
   *   The label of the entity, or NULL if there is no label defined.
   */
  public function label();
+1 −1
Original line number Diff line number Diff line
@@ -352,7 +352,7 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA
    $entities = $this->entityTypeManager->getStorage($target_type)->loadMultiple($result);
    foreach ($entities as $entity_id => $entity) {
      $bundle = $entity->bundle();
      $options[$bundle][$entity_id] = Html::escape($this->entityRepository->getTranslationFromContext($entity)->label());
      $options[$bundle][$entity_id] = Html::escape($this->entityRepository->getTranslationFromContext($entity)->label() ?? '');
    }

    return $options;
+2 −2
Original line number Diff line number Diff line
@@ -546,10 +546,10 @@ public function testBlockAccess() {
   * Tests block_user_role_delete.
   */
  public function testBlockUserRoleDelete() {
    $role1 = Role::create(['id' => 'test_role1', 'name' => $this->randomString()]);
    $role1 = Role::create(['id' => 'test_role1', 'label' => 'Test role 1']);
    $role1->save();

    $role2 = Role::create(['id' => 'test_role2', 'name' => $this->randomString()]);
    $role2 = Role::create(['id' => 'test_role2', 'label' => 'Test role 2']);
    $role2->save();

    $block = Block::create([
Loading