Archive for category Drupal 8

Link to entity

This Drupal module provides two field formatter for displaying entity reference field.

Link entity belongs to formatter

Link entity belongs to formatter link the current entity to the entity it belongs to. for example, terms in the tags if you want to redirect to node instead of term page.

Link entity query parameter formatter

Link entity as query parameter formatter link the current entity to any specific page and as the query parameter of that field. You have setting page to set the page and query parameter name you need to. for example, category in faq node if you want to /faq view page with filter tid.

How it work

– Create entity reference field the content types.
– Choose the formatter you want to use.
– Start adding content with field.
– See how it works ūüôā

https://www.drupal.org/project/link_to_entity

Advertisements

, , ,

Leave a comment

Nice blog to know how override views template in drupal 8

This is one if the blog post regarding views template override in Drupal 8

check the link below:-

http://redcrackle.com/blog/drupal-8/theme-views-templates

Leave a comment

How to get fields list in drupal 8

If you want to get all field list of a specific field type in Drupal 8 there is a easiest way to get them. Lets say you want to get all entity reference fields from all content types.

You just need to use this function in your class. You also need to load entity manager service into class.

<?php
$ref_fields = $this->entityManager->getStorage('field_storage_config')->loadByProperties(
      array(
        'settings' => array(
          'target_type' => 'node',
        ),
        'entity_type' => 'node',
        'type' => 'entity_reference',
        'deleted' => FALSE,
        'status' => 1,
      )
    );

Leave a comment

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

Leave a comment

Create own service for your module in Drupal 8

It is always good to know how to use core services and as well how to create your own service. Following code snippet can help you to do that.

Create custom service into modulename.service.yml

services:
  content_connected.manager:
    class: Drupal\content_connected\ContentConnectedManager
    arguments: ["@entity.manager", "@config.factory","@entity.query", "@module_handler","@renderer","@string_translation"]

You can see the details code in (http://cgit.drupalcode.org/content_connected?h=8.x-1.x)

Module link :- https://www.drupal.org/project/content_connected

,

Leave a comment