Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/field_ui/src/FieldUI.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\field_ui; | |
4 | |
5 use Drupal\Component\Utility\UrlHelper; | |
6 use Drupal\Core\Entity\EntityTypeInterface; | |
7 use Drupal\Core\Url; | |
8 | |
9 /** | |
10 * Static service container wrapper for Field UI. | |
11 */ | |
12 class FieldUI { | |
13 | |
14 /** | |
15 * Returns the route info for the field overview of a given entity bundle. | |
16 * | |
17 * @param string $entity_type_id | |
18 * An entity type. | |
19 * @param string $bundle | |
20 * The entity bundle. | |
21 * | |
22 * @return \Drupal\Core\Url | |
23 * A URL object. | |
24 */ | |
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)); | |
29 } | |
30 } | |
31 | |
32 /** | |
33 * Returns the next redirect path in a multipage sequence. | |
34 * | |
35 * @param array $destinations | |
36 * An array of destinations to redirect to. | |
37 * | |
38 * @return \Drupal\Core\Url|null | |
39 * The next destination to redirect to. | |
40 */ | |
41 public static function getNextDestination(array $destinations) { | |
42 // If there are no valid destinations left, return here. | |
43 if (empty($destinations)) { | |
44 return NULL; | |
45 } | |
46 | |
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' => [], | |
52 ]; | |
53 $next_destination = Url::fromRoute($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']); | |
54 } | |
55 else { | |
56 $options = UrlHelper::parse($next_destination); | |
57 if ($destinations) { | |
58 $options['query']['destinations'] = $destinations; | |
59 } | |
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); | |
63 } | |
64 return $next_destination; | |
65 } | |
66 | |
67 /** | |
68 * Gets the route parameter that should be used for Field UI routes. | |
69 * | |
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 | |
73 * The bundle name. | |
74 * | |
75 * @return array | |
76 * An array that can be used a route parameter. | |
77 */ | |
78 public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle) { | |
79 $bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle'; | |
80 return [$bundle_parameter_key => $bundle]; | |
81 } | |
82 | |
83 } |