function ConfigEntityValidationTestBase::setLabel

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::setLabel()

Sets the label of the given config entity.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The config entity to modify.

string $label: The label to set.

See also

::testLabelValidation()

1 call to ConfigEntityValidationTestBase::setLabel()
ConfigEntityValidationTestBase::testLabelValidation in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php
Tests validation of config entity's label.
1 method overrides ConfigEntityValidationTestBase::setLabel()
BlockValidationTest::setLabel in core/modules/block/tests/src/Kernel/BlockValidationTest.php
Sets the label of the given config entity.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php, line 372

Class

ConfigEntityValidationTestBase
Base class for testing validation of config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

protected static function setLabel(ConfigEntityInterface $entity, string $label) : void {
    $label_property = $entity->getEntityType()
        ->getKey('label');
    if ($label_property === FALSE) {
        throw new \LogicException(sprintf('Override %s to allow testing a %s without a label.', __METHOD__, (string) $entity->getEntityType()
            ->getSingularLabel()));
    }
    $entity->set($label_property, $label);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.