3 namespace Drupal\field_ui;
5 use Drupal\Component\Utility\UrlHelper;
6 use Drupal\Core\Entity\EntityTypeInterface;
10 * Static service container wrapper for Field UI.
15 * Returns the route info for the field overview of a given entity bundle.
17 * @param string $entity_type_id
19 * @param string $bundle
22 * @return \Drupal\Core\Url
25 public static function getOverviewRouteInfo($entity_type_id, $bundle) {
26 $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
27 if ($entity_type->get('field_ui_base_route')) {
28 return new Url("entity.{$entity_type_id}.field_ui_fields", static::getRouteBundleParameter($entity_type, $bundle));
33 * Returns the next redirect path in a multipage sequence.
35 * @param array $destinations
36 * An array of destinations to redirect to.
38 * @return \Drupal\Core\Url|null
39 * The next destination to redirect to.
41 public static function getNextDestination(array $destinations) {
42 // If there are no valid destinations left, return here.
43 if (empty($destinations)) {
47 $next_destination = array_shift($destinations);
48 if (is_array($next_destination)) {
49 $next_destination['options']['query']['destinations'] = $destinations;
50 $next_destination += [
51 'route_parameters' => [],
53 $next_destination = Url::fromRoute($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
56 $options = UrlHelper::parse($next_destination);
58 $options['query']['destinations'] = $destinations;
60 // Redirect to any given path within the same domain.
61 // @todo Revisit this in https://www.drupal.org/node/2418219.
62 $next_destination = Url::fromUserInput('/' . $options['path'], $options);
64 return $next_destination;
68 * Gets the route parameter that should be used for Field UI routes.
70 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
71 * The actual entity type, not the bundle (e.g. the content entity type).
72 * @param string $bundle
76 * An array that can be used a route parameter.
78 public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle) {
79 $bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle';
80 return [$bundle_parameter_key => $bundle];