Archive for category Uncategorized

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

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

Dynamically change Iframe height for cross domain site.

If you want to make iframe height change dynamically according to content then just use this. .-)

##### External site HTML #####

Add iframe tag with src.
Add js file from library:- http://INCLUDE-JS-FILE_PATH/iframeResizer.min.js

call js function :-

iFrameResize({log:false});

######

It works using iframe-resizer framework. So the iframe source page also need to include one js file as well.

#### Iframe content site #####
Add js file from library:-
http://INCLUDE-JS-FILE_PATH/js/iframeResizer.contentWindow.min.js

### GIT REPO of Iframe resizer framework(See example/index.html and example/frame.content.html ) ###

https://github.com/davidjbradshaw/iframe-resizer

Leave a comment

[SOLVED] [Drupal Webform] Altering a Webform’s submit button to an image causes it to stop working

[SOLVED] [Drupal Webform] Altering a Webform’s submit button to an image causes it to stop working

Styling a Webform is more or less like styling any other ordinary HTML form. Often you would like to change the style of the submit button and replace it with an image via code in your Drupal website. Although this is extremely easy it might cause the button to stop working, forcing it to reload and fail to show the confirmation message. If you are facing this problem while styling your Webform in your Drupal website read on to find the solution.  

,

Leave a comment

how to write php string variable in javascript function

‘<div onclick= “show_ajax_next(4,5,'’.$ajax.’','’.$form_id.’');”>’ . t(”) . ‘</div>’

in short  –'’.$ajax.’&#039–;

In place of “‘” (single quote) use ‘'’

 

Leave a comment

Remove playlist or recommended video from youtube video

Hi,

Many people will face this problem. Sometimes we show you tube videos in our site but we do not want to show the playlist or recommended videos at the end of video.

It is very easy to remove just adding ?rel=0 at the end of you tube video link!

example :http://www.youtube.com/watch?v=dPXFTxNrXEI?rel=0

Leave a comment