Posts Tagged drupal8

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

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

Content_connected module in drupal.org

Content connected is a lightweight module which allow administer to know whether content is connected with some other content before it is about to be deleted from the system. So administer should know whether content should be deleted or not.

Content connected is also added as sub tab in node pages to view content connection with other contents. This can be restricted by permissions for different roles.

Content connection based on entity reference field and any textarea/long field for any content type.

Connected content is listed in a table where it can be identified how it is connected(Reference field or textarea/long field).

, ,

Leave a comment

Similarterms module in drupal.org

This Drupal module attempts to provide context for content items by displaying a view block with links to other similar content. Similarity is based on the taxonomy terms assigned to content. Views are available based on similarity within each of the defined vocabularies for a site as well as similarity within all vocabularies.

What does this really mean? How should you use this module?

1) Create a freetagging vocabulary called “Tags” assigned to the content types on which you’d like to display the “Similar” view block.
2) Enable the view block called “Similar entries from the Tags vocabulary”.
3) Add keyword tags to the content.

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

, , ,

Leave a comment