You are here

public function SchedulerSetupTrait::entityAddUrl in Scheduler 2.x

Returns the url for adding an entity, for use in drupalGet().

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\Url The url object for adding the required entity.

18 calls to SchedulerSetupTrait::entityAddUrl()
SchedulerDefaultTimeTest::testDefaultTime in tests/src/Functional/SchedulerDefaultTimeTest.php
Test the default time functionality during content creation and edit.
SchedulerDefaultTimeTest::testDefaultWithHiddenTime in tests/src/Functional/SchedulerDefaultTimeTest.php
Test that the default times are set if the form time elements are hidden.
SchedulerFieldsDisplayTest::testDisabledFields in tests/src/Functional/SchedulerFieldsDisplayTest.php
Tests the edit form when scheduler fields have been disabled.
SchedulerFieldsDisplayTest::testHideSeconds in tests/src/Functional/SchedulerFieldsDisplayTest.php
Test the option to hide the seconds on the time input fields.
SchedulerFieldsDisplayTest::testVerticalTabOrFieldset in tests/src/Functional/SchedulerFieldsDisplayTest.php
Tests date input is displayed as vertical tab or an expandable fieldset.

... See full list

File

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

Class

SchedulerSetupTrait
Generic setup for all Scheduler tests.

Namespace

Drupal\Tests\scheduler\Traits

Code

public function entityAddUrl(string $entityTypeId, string $bundle = NULL) {
  switch ($entityTypeId) {
    case 'node':
      $bundle = $bundle == 'non-enabled' ? $this->nonSchedulerType : $bundle ?? $this->type;
      $route = 'node.add';
      $type_parameter = 'node_type';
      break;
    case 'media':
      $bundle = $bundle == 'non-enabled' ? $this->nonSchedulerMediaTypeName : $bundle ?? $this->mediaTypeName;
      $route = 'entity.media.add_form';
      $type_parameter = 'media_type';
      break;
    case 'commerce_product':
      $bundle = $bundle == 'non-enabled' ? $this->nonSchedulerProductTypeName : $bundle ?? $this->productTypeName;
      $route = 'entity.commerce_product.add_form';
      $type_parameter = 'commerce_product_type';
      break;
    default:
  }
  if (!($url = Url::fromRoute($route, [
    $type_parameter => $bundle,
  ]))) {

    // Incorrect parameter values.
    throw new \Exception(sprintf('Invalid entityTypeId "%s" or bundle "%s" passed to entityAddUrl()', $entityTypeId, $bundle));
  }
  return $url;
}