-
Recuperare l'url del sito corrente:
- $hostName = \Drupal::request()->getHost();
- $hostWithHttp = \Drupal::request()->getSchemeAndHttpHost();
-
Data di oggi:
- creation=(new \DateTime())->format('Y-m-d H:i:s');
-
Recuperare un nodo:
- $node = \Drupal\node\Entity\Node::load($nid);
- Elenco degli hook utilizzabili in un modulo (API)
-
Recuperare entità :
- $forms = Drupal::service('entity.query')->get('webform')->execute();
- $forms = \Drupal::entityQuery('webform')->condition('category', 'Revisioni')->execute();
-
$comment_count = \Drupal::entityQuery('comment')->count()->execute();
-
$ids= Drupal::service('entity.query') ->get('node')->condition('field_something', 'some_value')->execute();
-
Invalidare la cache (usando i tags):
- Vista: \Drupal::service('cache_tags.invalidator')->invalidateTags(array ('config:views.view.nodedeadlineview'));
- Effettuare una redirect verso un nodo ben preciso:
$routeName = 'entity.node.canonical'; $routeParameters = ['node' => $nodeid]; $url = \Drupal::url($routeName, $routeParameters); return new RedirectResponse($url);