Skip to main content

Posts

Views Template rendering in Drupal 8

File name suggessations are as follows:  [base template name]--[view machine name]--[view display id].html.twig [base template name]--[view machine name]--[view display type].html.twig [base template name]--[view display type].html.twig [base template name]--[view machine name].html.twig [base template name].html.twig example I used for an "unformatted list" with machine name "view_name" and with a single block, "block_1" views-view-unformatted--view-name--block-1.html.twig Custom Theme template with modules module name = product_view Add .module file /**  * Implements hook_theme().  */ function product_view_theme() {   return [     'product_view' => [       'variables' => [         'product_info' => [],       ],     ],   ]; } In controller return the theme with data:: $aa = array ( 'name' => 'raj' , 'age' => 20 );...

Angular 6/7 basic commands

To set up a new project in angular Download the angular code:  npm install -g @angular/cli install the project ng new project_name ng serve --open --port 42001 ng generate component home ng generate service hero Add Bootstarp 4 in Angular 7  1- npm install bootstrap --save  2- Add css in angular.json file in styles array key ( "node_modules/bootstrap/dist/css/bootstrap.min.css" )  3- Hit ng serve  Download and run Angular Project in local machie:  git clone https://github.com/angular/quickstart.git quickstart npm install (It will download the required modules according to the package.json) npm start or ng serve Live reload not working when change code,  then use sudo ng serve --port 4203 How to use Subscribe in angular when deal with http client with GET/POST menus : Topmenu [] = []; constructor ( private TopmenuService : TopmenuService ) { } ngOnInit () { this . getHeaderMenus (); } getHeaderMenus (...

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