You are here

public function SchedulerSetupTrait::entityTypeObject in Scheduler 2.x

Returns the stored entity type object from a type id and bundle id.

This allows previous usages of $this->nodetype to be replaced by entityTypeObject($entityTypeId) or entityTypeObject($entityTypeId, $bundle) when expanding tests to cover Media and Product entities.

Parameters

string $entityTypeId: The machine id of the entity type - 'node', 'media', 'commerce_product'.

string $bundle: The machine name of the bundle, for example 'testpage', 'test_video', 'not_for_scheduler', etc. Optional. Defaults to the enabled bundle. Also accepts the fixed string 'non-enabled' to indicate the non-enabled bundle for the entity type.

Return value

\Drupal\Core\Entity\EntityTypeInterface The stored entity type object.

10 calls to SchedulerSetupTrait::entityTypeObject()
SchedulerDevelGenerateTest::testDevelGenerate in tests/src/Functional/SchedulerDevelGenerateTest.php
Test the functionality that Scheduler adds during entity generation.
SchedulerFieldsDisplayTest::testDisabledFields in tests/src/Functional/SchedulerFieldsDisplayTest.php
Tests the edit form when scheduler fields have been disabled.
SchedulerFieldsDisplayTest::testManageFormDisplay in tests/src/Functional/SchedulerFieldsDisplayTest.php
Tests the settings entry in the content type form display.
SchedulerFieldsDisplayTest::testVerticalTabOrFieldset in tests/src/Functional/SchedulerFieldsDisplayTest.php
Tests date input is displayed as vertical tab or an expandable fieldset.
SchedulerJavascriptDefaultTimeTest::testTimeWhenSchedulingIsRequired in tests/src/FunctionalJavascript/SchedulerJavascriptDefaultTimeTest.php
Test the default time functionality when scheduling dates are required.

... See full list

File

tests/src/Traits/SchedulerSetupTrait.php, line 318

Class

SchedulerSetupTrait
Generic setup for all Scheduler tests.

Namespace

Drupal\Tests\scheduler\Traits

Code

public function entityTypeObject(string $entityTypeId, string $bundle = NULL) {
  switch (TRUE) {
    case $entityTypeId == 'node' && (empty($bundle) || $bundle == $this->type):
      return $this->nodetype;
    case $entityTypeId == 'node' && ($bundle == 'non-enabled' || $bundle == $this->nonSchedulerType):
      return $this->nonSchedulerNodeType;
    case $entityTypeId == 'media' && (empty($bundle) || $bundle == $this->mediaTypeName):
      return $this->mediaType;
    case $entityTypeId == 'media' && ($bundle == 'non-enabled' || $bundle == $this->nonSchedulerMediaTypeName):
      return $this->nonSchedulerMediaType;
    case $entityTypeId == 'commerce_product' && (empty($bundle) || $bundle == $this->productTypeName):
      return $this->productType;
    case $entityTypeId == 'commerce_product' && ($bundle == 'non-enabled' || $bundle == $this->nonSchedulerProductTypeName):
      return $this->nonSchedulerProductType;
    default:

      // Incorrect parameter values.
      throw new \Exception(sprintf('Unrecognised entityTypeId and bundle combination "%s" and "%s" passed to entityTypeObject()', $entityTypeId, $bundle));
  }
}