Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\field_ui;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\UrlHelper;
|
Chris@0
|
6 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
7 use Drupal\Core\Url;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Static service container wrapper for Field UI.
|
Chris@0
|
11 */
|
Chris@0
|
12 class FieldUI {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Returns the route info for the field overview of a given entity bundle.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @param string $entity_type_id
|
Chris@0
|
18 * An entity type.
|
Chris@0
|
19 * @param string $bundle
|
Chris@0
|
20 * The entity bundle.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @return \Drupal\Core\Url
|
Chris@0
|
23 * A URL object.
|
Chris@0
|
24 */
|
Chris@0
|
25 public static function getOverviewRouteInfo($entity_type_id, $bundle) {
|
Chris@0
|
26 $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
|
Chris@0
|
27 if ($entity_type->get('field_ui_base_route')) {
|
Chris@0
|
28 return new Url("entity.{$entity_type_id}.field_ui_fields", static::getRouteBundleParameter($entity_type, $bundle));
|
Chris@0
|
29 }
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Returns the next redirect path in a multipage sequence.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @param array $destinations
|
Chris@0
|
36 * An array of destinations to redirect to.
|
Chris@0
|
37 *
|
Chris@0
|
38 * @return \Drupal\Core\Url|null
|
Chris@0
|
39 * The next destination to redirect to.
|
Chris@0
|
40 */
|
Chris@0
|
41 public static function getNextDestination(array $destinations) {
|
Chris@0
|
42 // If there are no valid destinations left, return here.
|
Chris@0
|
43 if (empty($destinations)) {
|
Chris@0
|
44 return NULL;
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 $next_destination = array_shift($destinations);
|
Chris@0
|
48 if (is_array($next_destination)) {
|
Chris@0
|
49 $next_destination['options']['query']['destinations'] = $destinations;
|
Chris@0
|
50 $next_destination += [
|
Chris@0
|
51 'route_parameters' => [],
|
Chris@0
|
52 ];
|
Chris@0
|
53 $next_destination = Url::fromRoute($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
|
Chris@0
|
54 }
|
Chris@0
|
55 else {
|
Chris@0
|
56 $options = UrlHelper::parse($next_destination);
|
Chris@0
|
57 if ($destinations) {
|
Chris@0
|
58 $options['query']['destinations'] = $destinations;
|
Chris@0
|
59 }
|
Chris@0
|
60 // Redirect to any given path within the same domain.
|
Chris@0
|
61 // @todo Revisit this in https://www.drupal.org/node/2418219.
|
Chris@0
|
62 $next_destination = Url::fromUserInput('/' . $options['path'], $options);
|
Chris@0
|
63 }
|
Chris@0
|
64 return $next_destination;
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * Gets the route parameter that should be used for Field UI routes.
|
Chris@0
|
69 *
|
Chris@0
|
70 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
Chris@0
|
71 * The actual entity type, not the bundle (e.g. the content entity type).
|
Chris@0
|
72 * @param string $bundle
|
Chris@0
|
73 * The bundle name.
|
Chris@0
|
74 *
|
Chris@0
|
75 * @return array
|
Chris@0
|
76 * An array that can be used a route parameter.
|
Chris@0
|
77 */
|
Chris@0
|
78 public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle) {
|
Chris@0
|
79 $bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle';
|
Chris@0
|
80 return [$bundle_parameter_key => $bundle];
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 }
|