Monday 11 December 2017

Is there a way in drupal 8 to tell if the current page is a node?

    \Drupal::request()->attributes->get('node');

Taken from here: https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal%3A%3Arequest/8

Now the docs say to never use this function, but I have used this to determine what kind of page I am on.

There is another function, but I am not sure it applies in your case:

https://api.drupal.org/api/drupal/core%21modules%21node%21node.module/function/node_is_page/8

At the very least, if you do not have an entity, you could mimic that in your code:

      $route_match = \Drupal::routeMatch();
      if ($route_match->getRouteName() == 'entity.node.canonical') {
        return true;
      }

Reference

Friday 8 December 2017

Get all nodes of given type in Drupal 8 (maybe with a help of loadMultiple())


$nids = \Drupal::entityQuery('node')->condition('type','my_custom_type')->execute();
$nodes =  \Drupal\node\Entity\Node::loadMultiple($nids);

Thursday 7 December 2017

Drupal 8 list all node types programatically

$types = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
$nodeTypes = ! empty($types) ? array_keys($types) : [];

echo '<pre>';print_r($nodeTypes);echo '</pre>';

Source: drupal.stackexchange answer

Parenting tips to inculcate learning habits in your kid

Parenting tips to inculcate learning habits in your kid Tip #1) Children do not learn things, they emitate. So, try to do things by yours...