ParamConverterInterface.php 1.73 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

namespace Drupal\Core\ParamConverter;

use Symfony\Component\Routing\Route;

/**
 * Interface for parameter converters.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Classes implementing this interface are responsible for converting a path
 * parameter to the object it represents.
 *
 * Here is an example path: /admin/structure/block/manage/{block}
 *
 * In this case, '{block}' would be the path parameter which should be turned
 * into a block object representing the block in question.
 *
 * ParamConverters are defined as services tagged with 'paramconverter', and are
 * managed by the 'paramconverter_manager' service.
 *
 * @see menu
 * @see \Drupal\Core\ParamConverter\ParamConverterManagerInterface
 * @see \Drupal\Core\ParamConverter\EntityConverter
24 25 26 27
 */
interface ParamConverterInterface {

  /**
28
   * Converts path variables to their corresponding objects.
29
   *
30 31 32 33 34 35 36 37 38 39 40 41
   * @param mixed $value
   *   The raw value.
   * @param mixed $definition
   *   The parameter definition provided in the route options.
   * @param string $name
   *   The name of the parameter.
   * @param array $defaults
   *   The route defaults array.
   *
   * @return mixed|null
   *   The converted parameter value.
   */
42
  public function convert($value, $definition, $name, array $defaults);
43 44 45 46 47 48 49 50

  /**
   * Determines if the converter applies to a specific route and variable.
   *
   * @param mixed $definition
   *   The parameter definition provided in the route options.
   * @param string $name
   *   The name of the parameter.
51
   * @param \Symfony\Component\Routing\Route $route
52 53 54 55 56
   *   The route to consider attaching to.
   *
   * @return bool
   *   TRUE if the converter applies to the passed route and parameter, FALSE
   *   otherwise.
57
   */
58 59
  public function applies($definition, $name, Route $route);

60
}