Skip to main content

Posts

Setup new git folder

Steps To Configure new folder git setup : git init git config --global user.name "username" git config --global user.email "xxxx@gmail.com" git remote add origin https://github.com/Dharmend/ang-my-dream-app.git git config core.filemode false git pull origin BRANCH_NAME ++++++++++++++++++++++++++++ get single branch checkout directly: git fetch origin BRANCH_NAME git checkout BRANCH_NAME +++++++    Get pull live brnach forcefully (override local files)  ++++++++++++++++ git reset --hard origin/BRANCH_NAME

Debug print drupal 8 variables

Use Devel and kint , and search Kint NOTE: Please make sure devel profile must be kint ksm($form);  // print the form with search option in kint 1 - $form_state->getValues(); // Shows all the form field value 2 -  $form_state->getUserInput(); //to get the user input including buttons clicked +++++++++++++++++++++++ dump(_context|keys) }} // in twig file Compare string in Twig file  {% set form_id = form.custom_data.form_id %} {% if form_id == "node_story_edit_form" %}  Yes i am here  {% endif %}    2 - get the # valued of form in twig templates, : All the array and object value can get by  dot(.) operation while # value get by direct array like  below, if($form['#form_id'] == 'node_video_form' || $form['#form_id'] == 'node_video_edit_form'){        $form['#custom_data'] = array('custom_form_id' => $form['#form_id']);    ksm($form); } in twig file : {{ kint(form['...

How to Create/Apply Patches in drupal git

======== git patch A- Create new branch fix the changes After fix add & commit now create the patch with in the patch directory Now i am at patch branch & compare the changes to master branch command : git format-patch master -o patches patches/ : in this folder create the patch files Examples1 :  git format-patch TARGET_BRANCH  -o PATCH_FOLDER/ Lets suppose we are in patch branch and i do 5 commits to this branch, now to create the patch we will match the code to the traget branch like master in our case, so all the codes which is present in patch branch & not availbale in master branch would be create as patch files, 1 commit for 1 patch. i.e we do 5 commits so 5 commit files will be generated, Here:  -o reprents to store the patch as a directory and specify the director name   Example 2 : Single patch file based on commit id Lets consider the above example, but now i need only one commit changes instead of all, so first check...

Alter entity value before save

How to list the name of Entity types in site to use hooks, use Drupal\Core\Entity\EntityInterface; function hook_entity_presave(EntityInterface $entity) { } or function hook_entity_type_presave(EntityInterface $entity) { } but you should know the exact name of entity type , to do so use : drupal debug:entity (drush command) so for taxonomy case use, function itg_multi_category_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {   if(!empty($entity->bundle()) && $entity->bundle() == 'category_management'){     $entity_values = $entity->toArray();     //Get the custom parent cat id      $parent_custom = $entity_values['field_relation'][0]['target_id'];     if($parent_custom == ''){       $parent_custom = 0;     }     $term_load = \Drupal\taxonomy\Entity\Term::load($entity_values['tid'][0]['value']);     $term_load->set('parent...

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...