Skip to main content

Posts

Showing posts from June, 2018

dynamic query in drupal 8

QUERY:1  $query = db_select('custom_live_blog','lb');     $query->fields('lb');     $query->condition('lb.blog_nid',$blog_nid);     $query->condition('lb.user_id',$user_id);     $result = $query->execute()->fetchAll();     return $result; Result

Get The field values of node in Drupal 8

use Drupal \ node \ NodeInterface ; /** * Implements hook_ENTITY_TYPE_insert() for node entities. * * This tests saving a node on node insert. * * @see \Drupal\node\Tests\NodeSaveTest::testNodeSaveOnInsert() */ function node_test_node_insert ( NodeInterface $node ) { // Set the node title to the node ID and save. if ( $node - > getTitle ( ) == 'new' ) { $node - > setTitle ( 'Node ' . $node - > id ( ) ) ; $node - > setNewRevision ( FALSE ) ; $node - > save ( ) ; } } Now There is so many functions are there to get the values, For All the functions available visit the API code, https://api.drupal.org/api/drupal/core%21modules%21node%21src%21NodeInterface.php/interface/NodeInterface/8.2.x Some of as below, Node edit form, Drupal 8 Automatically Load the whole object no need to load the entity like below, if ($event->getFormId() == 'node_alexa_audio_clips_edit_form') { $node = \Drupal::ro...

How to theme form in Drupal 8

https://www.bryanbraun.com/2013/08/17/using-hook-form-base-form-id-alter/ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; /* * Implement hook_form_base_id_alter() */ function atadmin_form_node_form_alter(&$form, FormStateInterface $form_state) { $node = $form_state->getFormObject()->getEntity(); if($form['#form_id'] == 'node_story_form' || $form['#form_id'] == 'node_story_edit_form'){ $form['#theme'] = array('at_node_story_form'); }elseif($form['#form_id'] == 'node_video_form' || $form['#form_id'] == 'node_video_edit_form'){ $form['#theme'] = array('at_node_video_form'); }elseif($form['#form_id'] == 'node_photo_gallery_form' || $form['#form_id'] == 'node_photo_gallery_edit_form'){ $form['#theme'] = array('at_node_photo_gallery_form'); }elseif($form['#form_id'] == 'node_po...

How to create drupal 8 multisite in localhost

Drupal has a multisite feature which means, you can run multiple sites with the single code base, but all the sites can have different databases, different configuration & files. For multisite installation on drupal 8, I am going to configure the three sites with single code base atdrupaldev.com btdrupaldev.localhost ithdrupaldev.localhost  Now the question is how to configure it, Let me explain each & every step. Follow the below steps, Step 1: Download the latest Drupal code and put it in your working directory,  for supposing I put the code in var/www/at-drupal-8 Step 2: Create the three databases from php myadmin or any GUI, Step 3: Now open the sites directory and copy the default folder & paste it three times and give names as the site name above, i.e default = atdrupaldev.com default = btdrupaldev.localhost default = ithdrupaldev.localhost So your folder structure would be like below, Step 4: Now provide the databas...

Basic Drush Commands for Drupal 8

Daily Use Drush commands for Drupal 8 Drush is used to perform some admin tasks from CLI , Drush command are different for drupal 7 & Drupal 8 versions, Here I am Providing some most  used drush commands for daily use. If you have more of them that you use regularly in your project, please put them in the comments, as I would love to add them to the list. To use these commands make sure you already installed drush on your system, if still you did't install the drush please install it, by the command sudo apt-get install drush or follow any other article to install it. Drush Command Usage drush cr cache rebuild to drupal drush dl {module_name} or {theme_name} to download the drupal module and themes drush en {module_name} or {theme_name} to enable the downloaded module and themes drush upwd --password="NewPassword" admin update the password of user admin drush sql-cli < ...