Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Saturday, November 17, 2018

Customization in drupal 8 core contact form using form alter

How to change Drupal 8 Core Contact form fleld label :-

 If you want to change Contact form "Message" field label you can use "hook_form_alter" .

either you can create a custom module or either you can add form alter in your theme file also.

 
function your_theme_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
       if ($form_id == 'contact_message_feedback_form') {
        $form['message']['widget'][0]['value']['#title'] = t("My Custom Body Label");
     }
} 


Add placeholder in default search using form alter

function your_theme_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    if (in_array($form_id, ['search_block_form', 'search_form'])) {
        $form['keys']['#attributes']['placeholder'] = t('Search...');
    }
   }if ($form_id == 'contact_message_feedback_form') {
  $form['actions']['submit']['#value'] = t("My Altered submit button text here");
  $form['subject']['widget'][0]['value']['#title'] = t ("My Altered title here");
  $form['message']['widget'][0]['value']['#title'] = t("My custom body text here");
        //$form['message']['widget'][0]['value']['#title'] = t("My Custom Body Label");
  $form['#suffix'] = "<div class='extra-text'><p>Show some text before the comment form.</p></div>";
     }
} 

Monday, October 29, 2018

How to Change 'Any' option in exposed filter in Drupal 8.




If you Want to Change label of "Any" in exposed filter option in Drupal 8. You can use "Better exposed filter" . here thesome step to change of Any text in D8.

Step 1 : Open your Better exposed filter setting and find out the filter in which you want to change the label.

Step 2: Scroll down at the bottom select  "More options for "field_ad_category_target_id(your filter name)".


Step 3 : Click on "Rewrite filter options"


Step 4 : put this in "Retrite the text option"

 example : - Any -| Your option

Step 5: in my case i want to change "Any" label to 'Your option'. i hope this will work for you :)

Wednesday, October 24, 2018

My trick to add Colorbox popup on Slideshow images in Drupal 8

Hello, If you want to show any slider image in the popup form on click on image
here is the my funny or easy trick to do it. i hope it will work for you :)

Trick 1 :-  I have a task that i have created a slider using image fieldslideshow , i have done this by using view and just set image formatter as image fieldslideshow but now requirement is that when we click on the image it should be open as colorbox popup.


solution : -
   step 1 :- I have added a same image field in view and set formatter "colorbox" and excluded that filed, its all because shwo we can found colorbox library on required page.

step 2 :-  just change twig file structure according colorbox :-

From :-

{% for key,value in url %}
            <img src="{{ value }}" />
        {% endfor %}


To :-

{% for key,value in url %}
    <a href="{{ value }}" class="colorbox cboxElement"><img src="{{ value }}" /></a>
    {% endfor %}

Step 3 :- Now you will be able to see popup on your slider image


Trick 2 - Need to add popup on field slide show image.

Step 1:- i have set filed slideshow on display format of image and link image to file.

Step 2:- create a other image field to and set Colorbox format to call Colorbox library, set a default image in this field, disable from disaplay form, and just add Css for display none.

Step 3 :- there is same structure which we want for colorbox popup except colorbox class so i have  added class using jquery

jQuery('.field--name-field-product-image .field-slideshow').find('a').addClass('colorbox cboxElement');

 


How to Show all products and node related to the node user



When we click on the node or product and you want to show show all the products related to the user who publish the current user. you have to apply filter user id filter i am showing you in the below post.


Step 1 : - Firstly you have to change the "url alias" for the node and need to add author name.

eg. if you have product content type your path pattern should be like              
 ( [node:title]/[node:author] ) this.

path pattern:- [node:title]/[node:author]


Step 2 :- You Need to add "user Name" contextual filter in the view block.
if your url link this ->  
http://115.166.142.238/souq_alhrag/ar/samsung-galaxy-j2-core/customer

http://<ip>/<projectname>/<language>/<nodeid>/<username>

select raw value under "Provide default value"and path alias 2 in my case.


Exclude current Node in Block view in Drupal 8

If you want to exclude current node and product in block view in drupal 8 pls follow the below steps.


Step 1 :-  Create a block view.

Step 2 :-  Add Content Under "Contextual Filters", select "Provide Default value"->"Content Id from url"


Step 3 :- Scroll Down at bottom and Check "Exclude" under "More".

 
Step 4 :- Apply filter and save changes , now only content id which is the url doesn't show in the block view.

Tuesday, October 23, 2018

Add Node as a popup in Drupal 7

How to Show Any Node in the popup form in Drupal 7 :-




If you want to Show any node or page in the poup form when click on the link add the link in this format in your block.

 <div><a class="colorbox-node colorbox-node-gallery" href="/disclaimer?width=600&height=600" rel="gallery">My Popup Example</a></div>