22
33namespace Drupal \template_whisperer \Controller ;
44
5+ use Drupal \Core \Pager \PagerManagerInterface ;
56use Drupal \template_whisperer \Entity \TemplateWhispererSuggestionEntityInterface ;
67use Drupal \Core \Controller \ControllerBase ;
78use Symfony \Component \DependencyInjection \ContainerInterface ;
@@ -35,13 +36,21 @@ class AdminSuggestionController extends ControllerBase {
3536 */
3637 protected $ urlGenerator ;
3738
39+ /**
40+ * The pager manager.
41+ *
42+ * @var \Drupal\Core\Pager\PagerManagerInterface
43+ */
44+ protected $ pagerManager ;
45+
3846 /**
3947 * Class constructor.
4048 */
41- public function __construct (EntityTypeManagerInterface $ entity_type_manager , TemplateWhispererSuggestionUsage $ tw_suggestion_usage , UrlGeneratorInterface $ url_generator ) {
49+ public function __construct (EntityTypeManagerInterface $ entity_type_manager , TemplateWhispererSuggestionUsage $ tw_suggestion_usage , UrlGeneratorInterface $ url_generator, PagerManagerInterface $ pager_manager ) {
4250 $ this ->entityTypeManager = $ entity_type_manager ;
4351 $ this ->twSuggestionUsage = $ tw_suggestion_usage ;
4452 $ this ->urlGenerator = $ url_generator ;
53+ $ this ->pagerManager = $ pager_manager ;
4554 }
4655
4756 /**
@@ -50,10 +59,11 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Tem
5059 public static function create (ContainerInterface $ container ) {
5160 // Instantiates this form class.
5261 return new static (
53- // Load the service required to construct this class.
54- $ container ->get ('entity_type.manager ' ),
55- $ container ->get ('template_whisperer.suggestion.usage ' ),
56- $ container ->get ('url_generator ' )
62+ // Load the service required to construct this class.
63+ $ container ->get ('entity_type.manager ' ),
64+ $ container ->get ('template_whisperer.suggestion.usage ' ),
65+ $ container ->get ('url_generator ' ),
66+ $ container ->get ('pager.manager ' )
5767 );
5868 }
5969
@@ -84,8 +94,8 @@ public function usage(TemplateWhispererSuggestionEntityInterface $template_whisp
8494 $ usages = $ this ->twSuggestionUsage ->listUsage ($ template_whisperer_suggestion );
8595 $ count = $ this ->twSuggestionUsage ->countUsage ($ template_whisperer_suggestion );
8696
97+ $ this ->pagerManager ->createPager ($ count , 30 );
8798 // Pager.
88- pager_default_initialize ($ count , 30 );
8999 $ output [] = [
90100 '#type ' => 'pager ' ,
91101 '#quantity ' => '3 ' ,
@@ -105,7 +115,7 @@ public function usage(TemplateWhispererSuggestionEntityInterface $template_whisp
105115
106116 // Build the table empty state.
107117 if (!empty ($ entity )) {
108- $ output ['table ' ][$ i ]['entity ' ] = ['#markup ' => '<a target="_blank" href=" ' . $ entity ->url () . '"> ' . $ entity ->getTitle () . '</a> ' ];
118+ $ output ['table ' ][$ i ]['entity ' ] = ['#markup ' => '<a target="_blank" href=" ' . $ entity ->toUrl ()-> toString () . '"> ' . $ entity ->getTitle () . '</a> ' ];
109119 }
110120 }
111121
0 commit comments