Hoppa till huvudinnehåll
Menu

Den här sidan använder cookies. Om du fortsätter använda sidan så accepterar du användandet av cookies. Läs mer om cookies

Jag förstår

Call core services of Drupal 8 via the service container

It is not very good way to call Drupal core services directly in the class. Try to avoid such code in your code. Intead of doing that you can inject core services through service containner. Following code will help you to know how you should do that. 

<?php

  /**
   * Database Service Object.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;


  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public static function create() {
    return new static($container->get('database'), $container->get('entity.manager')->getStorage('taxonomy_vocabulary')
    );


  public function validatefunction($arg) { 
    $select = $this->connection->select('taxonomy_index', 'ti')->fields('ti', array('tid'));
    $result = $select->execute();
   }
}

So intead of calling $connection = \Drupal::database(); , you should inject core services into your class visa container service. 

Details code you can found :-  http://cgit.drupalcode.org/similarterms/tree/views/similarterms_handler_argument_node_nid.inc

Helpful information to read :- https://www.drupal.org/node/2133171

Vi hjälper dig nå resultat. Kontakta oss Ring direkt på 08-20 90 04.

Cache in Drupal 8: How it worked, and what we wanted to be solved in D8

If you just want your content to be cached before Drupal 8, there were almost no problems, just turn on caching for anonymou…
MDN

Cache in Drupal 8: Introduction

In a series of blog posts we will go through how caching works in Drupal 8, to try to demystify the caching layer in Drupal …
MDN

Updating taxonomy term name in Drupal 8

Here you can read how to use hook update for updating taxonomy terms in Drupal 8.