Routing http://lobsterr.me/ en How to provide full access to route in Drupal? http://lobsterr.me/post/how-provide-full-access-route-drupal <span class="field field--name-title field--type-string field--label-hidden">How to provide full access to route in Drupal?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">03/17/2021</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>Let's imagine we don't want to have any restrictions for our route. For this we can set <strong>_access </strong>requirement to <strong>TRUE</strong>.</p> <pre> <code class="language-php">your_module.route_name: path: '/your_path' defaults: _controller: 'Drupal\your_module\Controller\YourController::yourMethod' requirements: _access: 'TRUE'</code></pre> <p> </p> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/routing-api" hreflang="en">Routing API</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing" hreflang="en">Routing</a></div> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Wed, 17 Mar 2021 13:10:49 +0000 LOBsTerr 44 at http://lobsterr.me How to get a route by URI in Drupal? http://lobsterr.me/post/how-get-route-uri-drupal <span class="field field--name-title field--type-string field--label-hidden">How to get a route by URI in Drupal?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">02/05/2021</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>If you have a basic path we can get route using <strong>router.no_access_checks</strong> service. Keep in my you have to have a leading slash</p> <pre> <code class="language-php">$router = \Drupal::service('router.no_access_checks'); $result = $router-&gt;match('/node/2'); </code></pre> <p>In case you have URL object we can get route from it like this</p> <pre> <code class="language-php">$router = \Drupal::service('router.no_access_checks'); $result = $router-&gt;match($url-&gt;toString());</code></pre> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing" hreflang="en">Routing</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing-api" hreflang="en">Routing API</a></div> </div> <div class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush"> <div class="field__label">Related items</div> <ul class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush field__items"> <li class="field__item list-group-item"><a href="/post/how-get-route-name-drupal-9" hreflang="en">How to get a route by name in Drupal 9?</a></li> <li class="field__item list-group-item"><a href="/post/how-check-if-current-page-using-admin-theme-drupal" hreflang="en">How to check if the current page using admin theme in Drupal?</a></li> </ul> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Fri, 05 Feb 2021 12:59:18 +0000 LOBsTerr 37 at http://lobsterr.me How to get a route by name in Drupal 9? http://lobsterr.me/post/how-get-route-name-drupal-9 <span class="field field--name-title field--type-string field--label-hidden">How to get a route by name in Drupal 9?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">02/05/2021</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>To get route by name in Drupal 9 we need to use <strong>router.route_provider </strong>service.</p> <pre> <code class="language-php">$route_provider = \Drupal::service('router.route_provider'); $route = $route_provider-&gt;getRouteByName('user.page');</code></pre> <p> </p> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing" hreflang="en">Routing</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing-api" hreflang="en">Routing API</a></div> </div> <div class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush"> <div class="field__label">Related items</div> <ul class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush field__items"> <li class="field__item list-group-item"><a href="/post/how-get-route-uri-drupal" hreflang="en">How to get a route by URI in Drupal?</a></li> <li class="field__item list-group-item"><a href="/post/how-check-if-current-page-using-admin-theme-drupal" hreflang="en">How to check if the current page using admin theme in Drupal?</a></li> </ul> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Fri, 05 Feb 2021 12:57:32 +0000 LOBsTerr 36 at http://lobsterr.me How to check if the current page using admin theme in Drupal? http://lobsterr.me/post/how-check-if-current-page-using-admin-theme-drupal <span class="field field--name-title field--type-string field--label-hidden">How to check if the current page using admin theme in Drupal?</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">LOBsTerr</span></span> <span class="field field--name-created field--type-created field--label-hidden">02/05/2021</span> <div class="field field--name-f-content field--type-entity-reference-revisions field--label-hidden field__items"> <div class="field__item"> <div class="paragraph paragraph--type--l-text paragraph--view-mode--default"> <div class="clearfix text-formatted field field--name-f-text field--type-text-long field--label-hidden field__item"><p>To check this we need to use router.admin_context service</p> <pre> <code class="language-php">if (\Drupal::service('router.admin_context')-&gt;isAdminRoute()) { // Do something here. }</code></pre> <p>We also can check a specific route</p> <pre> <code class="language-php">$route_provider = \Drupal::service('router.route_provider'); $route = $route_provider-&gt;getRouteByName('user.page'); if (\Drupal::service('router.admin_context')-&gt;isAdminRoute($route)) { // Do something here. }</code></pre> <p> </p> </div> </div> </div> </div> <div class="field field--name-f-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item btn btn-secondary"><a href="/tags/drupal-9" hreflang="en">Drupal 9</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing" hreflang="en">Routing</a></div> <div class="field__item btn btn-secondary"><a href="/tags/routing-api" hreflang="en">Routing API</a></div> </div> <div class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush"> <div class="field__label">Related items</div> <ul class="field field--name-f-related-items field--type-entity-reference field--label-above list-group list-group-flush field__items"> <li class="field__item list-group-item"><a href="/post/how-get-route-uri-drupal" hreflang="en">How to get a route by URI in Drupal?</a></li> <li class="field__item list-group-item"><a href="/post/how-get-route-name-drupal-9" hreflang="en">How to get a route by name in Drupal 9?</a></li> </ul> </div> <section class="field field--name-f-comments field--type-comment field--label-above comment-wrapper"> </section> Fri, 05 Feb 2021 12:52:16 +0000 LOBsTerr 35 at http://lobsterr.me