FieldUI.php 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\field_ui\FieldUI.
 */

namespace Drupal\field_ui;

10
use Drupal\Component\Utility\UrlHelper;
11
use Drupal\Core\Url;
12

13 14 15 16 17
/**
 * Static service container wrapper for Field UI.
 */
class FieldUI {

18 19 20
  /**
   * Returns the route info for the field overview of a given entity bundle.
   *
21
   * @param string $entity_type_id
22 23 24 25
   *   An entity type.
   * @param string $bundle
   *   The entity bundle.
   *
26 27
   * @return \Drupal\Core\Url
   *   A URL object.
28
   */
29 30
  public static function getOverviewRouteInfo($entity_type_id, $bundle) {
    $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
31
    if ($entity_type->get('field_ui_base_route')) {
32 33 34
      return new Url("field_ui.overview_$entity_type_id", array(
        $entity_type->getBundleEntityType() => $bundle,
      ));
35 36 37
    }
  }

38 39 40
  /**
   * Returns the next redirect path in a multipage sequence.
   *
41 42 43
   * @param array $destinations
   *   An array of destinations to redirect to.
   *
44
   * @return \Drupal\Core\Url
45
   *   The next destination to redirect to.
46
   */
47 48 49 50
  public static function getNextDestination(array $destinations) {
    $next_destination = array_shift($destinations);
    if (is_array($next_destination)) {
      $next_destination['options']['query']['destinations'] = $destinations;
51 52 53
      $next_destination += array(
        'route_parameters' => array(),
      );
54
      $next_destination = new Url($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
55 56
    }
    else {
57
      $options = UrlHelper::parse($next_destination);
58 59 60
      if ($destinations) {
        $options['query']['destinations'] = $destinations;
      }
61 62
      $next_destination = Url::createFromPath($options['path']);
      $next_destination->setOptions($options);
63 64 65 66 67
    }
    return $next_destination;
  }

}