You are here

protected function SchedulerHooksTest::approveEntity in Scheduler 2.x

Approves an entity for publication or unpublication.

Parameters

string $entityTypeId: The entity type to approve, 'node' or 'media'.

int $id: The id of the entity to approve.

string $field_name: The name of the field to set, either 'field_approved_publishing' or 'field_approved_unpublishing'.

2 calls to SchedulerHooksTest::approveEntity()
SchedulerHooksTest::testPublishingAllowed in tests/src/Functional/SchedulerHooksTest.php
Covers hook_scheduler_{type}_publishing_allowed()
SchedulerHooksTest::testUnpublishingAllowed in tests/src/Functional/SchedulerHooksTest.php
Covers hook_scheduler_{type}_unpublishing_allowed()

File

tests/src/Functional/SchedulerHooksTest.php, line 405

Class

SchedulerHooksTest
Tests the API hook functions of the Scheduler module.

Namespace

Drupal\Tests\scheduler\Functional

Code

protected function approveEntity($entityTypeId, $id, $field_name) {
  $storage = $this
    ->entityStorageObject($entityTypeId);
  $storage
    ->resetCache([
    $id,
  ]);
  $entity = $storage
    ->load($id);
  $entity
    ->set($field_name, TRUE);
  $label_field = $entity
    ->getEntityType()
    ->get('entity_keys')['label'];
  $entity
    ->set($label_field, $entity
    ->label() . " - approved for publishing: {$entity->field_approved_publishing->value}, for unpublishing: {$entity->field_approved_unpublishing->value}")
    ->save();
}