diff --git a/core/core.services.yml b/core/core.services.yml index ce89b92..e5a7d60 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1644,4 +1644,4 @@ services: - { name: event_subscriber } pager.factory: class: Drupal\Core\Pager\PagerFactory - arguments: ['@service_container', '@request_stack'] + arguments: ['@request_stack'] diff --git a/core/lib/Drupal/Core/Pager/Pager.php b/core/lib/Drupal/Core/Pager/Pager.php index b5bf334..2acda0a 100644 --- a/core/lib/Drupal/Core/Pager/Pager.php +++ b/core/lib/Drupal/Core/Pager/Pager.php @@ -3,7 +3,6 @@ namespace Drupal\Core\Pager; use Drupal\Core\Url; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Pager class. @@ -59,23 +58,14 @@ class Pager implements PagerInterface { /** * Constructs a new Pager object. * + * @param int $element + * The pager element that uniquely identifies this pager object. * @param \Drupal\Core\Pager\PagerFactoryInterface $pager_factory * The pager factory. */ - public function __construct(PagerFactoryInterface $pager_factory) { + public function __construct($element, PagerFactoryInterface $pager_factory) { + $this->element = $element; $this->factory = $pager_factory; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $element) { - $instance = new static( - $container->get('pager.factory') - ); - - // Set the pager element. - $instance->element = $element; // @todo: Start of BC layer. This maps the pager properties to the global // pager variables of D8. When removing the global variables in D9, remove @@ -84,22 +74,20 @@ public static function create(ContainerInterface $container, $element) { if (!isset($pager_page_array[$element])) { $pager_page_array[$element] = NULL; } - $instance->currentPage = &$pager_page_array[$element]; + $this->currentPage = &$pager_page_array[$element]; if (!isset($pager_total[$element])) { $pager_total[$element] = NULL; } - $instance->totalPages = &$pager_total[$element]; + $this->totalPages = &$pager_total[$element]; if (!isset($pager_total_items[$element])) { $pager_total_items[$element] = NULL; } - $instance->totalItems = &$pager_total_items[$element]; + $this->totalItems = &$pager_total_items[$element]; if (!isset($pager_limits[$element])) { $pager_limits[$element] = NULL; } - $instance->limit = &$pager_limits[$element]; + $this->limit = &$pager_limits[$element]; // @todo: End of BC layer. - - return $instance; } /** diff --git a/core/lib/Drupal/Core/Pager/PagerFactory.php b/core/lib/Drupal/Core/Pager/PagerFactory.php index 1dd8114..23eb74a 100644 --- a/core/lib/Drupal/Core/Pager/PagerFactory.php +++ b/core/lib/Drupal/Core/Pager/PagerFactory.php @@ -3,7 +3,6 @@ namespace Drupal\Core\Pager; use Drupal\Component\Utility\UrlHelper; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -19,13 +18,6 @@ class PagerFactory implements PagerFactoryInterface { protected $pagers = []; /** - * The service container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** * The request stack object. * * @var \Symfony\Component\HttpFoundation\RequestStack @@ -35,13 +27,10 @@ class PagerFactory implements PagerFactoryInterface { /** * Constructs a new PagerFactory object. * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The service container. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. */ - public function __construct(ContainerInterface $container, RequestStack $request_stack) { - $this->container = $container; + public function __construct(RequestStack $request_stack) { $this->requestStack = $request_stack; } @@ -55,7 +44,7 @@ public function __construct(ContainerInterface $container, RequestStack $request * The pager object. */ protected function create($element) { - return Pager::create($this->container, $element); + return new Pager($element, $this); } /** diff --git a/core/lib/Drupal/Core/Pager/PagerInterface.php b/core/lib/Drupal/Core/Pager/PagerInterface.php index ecde698..f29f401 100644 --- a/core/lib/Drupal/Core/Pager/PagerInterface.php +++ b/core/lib/Drupal/Core/Pager/PagerInterface.php @@ -10,21 +10,6 @@ interface PagerInterface { /** - * Instantiates a new instance of this class. - * - * This is a factory method that returns a new instance of this class. The - * factory should pass any needed dependencies into the constructor of this - * class, but not the container itself. Every call to this method must return - * a new instance of this class; that is, it may not implement a singleton. - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The service container this instance should use. - * @param int $element - * The pager element that uniquely identifies this pager object. - */ - public static function create(ContainerInterface $container, $element); - - /** * Gets the pager element. * * The pager element is the index that uniquely identifies the relevant pager diff --git a/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php b/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php index 273a7c5..587076d 100644 --- a/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php @@ -36,16 +36,14 @@ protected function setUp() { global $pager_page_array, $pager_total, $pager_total_items, $pager_limits; $pager_page_array = $pager_total = $pager_total_items = $pager_limits = NULL; - $container = new ContainerBuilder(); $request_stack = $this->getMockBuilder(RequestStack::class)->getMock(); $query = new ParameterBag(['foo' => 'bar', 'qux' => 'dee']); $this->pagerFactory = $this ->getMockBuilder(PagerFactory::class) ->setMethods(['getCurrentRequestQuery']) - ->setConstructorArgs([$container, $request_stack]) + ->setConstructorArgs([$request_stack]) ->getMock(); - $container->set('pager.factory', $this->pagerFactory); $this->pagerFactory->expects($this->any()) ->method('getCurrentRequestQuery') diff --git a/core/tests/Drupal/Tests/Core/Pager/PagerTest.php b/core/tests/Drupal/Tests/Core/Pager/PagerTest.php index 88673f7..aa3e77f 100644 --- a/core/tests/Drupal/Tests/Core/Pager/PagerTest.php +++ b/core/tests/Drupal/Tests/Core/Pager/PagerTest.php @@ -32,12 +32,10 @@ class PagerTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { - $container = new ContainerBuilder(); $pager_factory = $this ->getMockBuilder(PagerFactory::class) ->disableOriginalConstructor() ->getMock(); - $container->set('pager.factory', $pager_factory); // Set pager query string parameter to 'page'. $pager_factory->expects($this->any()) @@ -53,7 +51,7 @@ protected function setUp() { ->will($this->returnValue(['rec' => 'lop', 'ste' => 'cik'])); // Pager for element 6. - $this->pager = Pager::create($container, 6); + $this->pager = new Pager(6, $pager_factory); // Set factory to return the test pager via ::all(). $pager_factory->expects($this->any())