вторник, 6 декабря 2011 г.

How to send email notifications for comments in Drupal 7 with actions & triggers

How to send email notifications for comments in Drupal 7 with actions & triggers

Drupal 7 cms logo Do you have a Drupal 7 web site? Do you want to get an email when someone comments, so you don't have to check your site all the time? Don't panic! Here's how you do it.
You don't need to install any new modules to do this in Drupal 7. All that's needed is a little configuring and to copy and paste in a short bit of code.


Step 1: Getting started

Go to the Modules page, and make sure that you enable the Trigger module (at Modules > Trigger) and turn on Clean URLs (at Administer > Configuration > Search and metadata). These are core modules/settings in Drupal 7, so you don't have to install them, just turn them on.
enabled checkbox for Trigger on the Modules pagelocation of Clean URLs in administrative interface

Step 2: Taking action

Your next step will be to create an action, so that drupal can perform it when a comment is saved.
Go to Configuration > System > Actions.
Actions link shown on Configuration page
On the Actions page, choose the dropdown for Create an Advanced Action at the bottom of the page, and click on Send email and then Create.
create an advanced action dropdown with Send email highlighted
On the Configure an advanced action page, fill in the first 3 fields, as in these examples:
  • Label: Send an email notification to site owner upon comment save
  • Recipient: siteowner@adellefrank.com
  • Subject: New Comment at AdelleFrank.com
The trickiest part of this entire endeavor is filling in the Message field, but here's some easy sample code that you could just copy and paste in:
### Node
[comment:node:title] at: [site:url]node/[comment:node:nid]#comment-[comment:cid]

### Comment
[comment:author:name]
[comment:title]
[comment:body]

### Review
[site:url]admin/content/comment/approval

Those bits of code within square brackets are called tokens. Tokens are placeholders, little bits of code that represent commonly-used values. To find more tokens in Drupal 7, you must have two modules enabled. First, turn on the core Help module, which you should have enabled anyway...because it's helpful.  However, I find it bizarre that, even though you're only using tokens included in the Core, you must still install and turn on the Token module, too.
Only then can you point your web browser to the Help > Token page at http://www.yoursite.com/admin/help/token and get a list of all the tokens you can choose among.

Step 3: Triggering your action

At the top of the page, click on the Triggers link to go to the next step. This page can also be found underneath Structure > Triggers.
Triggers link shown at top of Actions page
Be sure to choose the comments tab on the Triggers page.
Comments tab shown at top of Triggers page
You have a number of choices, but since mine is a solo blog, Trigger: After saving a new comment seems most appropriate. Click on the dropdown instructing you to Choose an action and click underneath system on the name of the Action (Send an email notification to site owner upon comment save) you created in Step 2 and then click Assign.
action selected on dropdown for Trigger: After saving a new comment
successfully assigned action to trigger

Step 4: Testing your comments form

Now, as far as you know, your web site is set up to email you when someone saves a comment.  To be absolutely certain that your new action and trigger are working correctly, you need to test it.
Browse to any page, article, or blog post on your site and post a comment.
Check your email at the address you chose in step 2. Does this email give you the information you expected?
Remember to delete your test comment off of your site.

For more information

Теммзация формы коментариев в Drupal 7

 
 
 
 
function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
  //dpm($form);  //shows original $form array
  $form['author']['#type'] = 'fieldset';
  $form['author']['#title'] = 'Your Information';
  $form['author']['#collapsible'] = FALSE;

  $form['your_comment'] = array(
    '#type' => 'fieldset',
    '#title' => t('Your Comment'),
    '#collapsible' => FALSE,
    '#weight' => 2,
  );

  //Subject
  $form['your_comment']['subject'] = $form['subject'];
  unset($form['subject']);
  $form['your_comment']['subject']['#weight'] = -10;

  //Comment
  $form['your_comment']['comment_body'] = $form['comment_body'];
  unset($form['comment_body']);

  $form['author']['homepage']['#access'] = FALSE;

  $form['author']['mail']['#required'] = TRUE;

  //dpm($form);  //shows $form array after our changes

}

Убрать подсказки по форматам в Drupal 7

function yourtheme_form_comment_form_alter(&$form, &$form_state, &$form_id)
{
  $form['comment_body']['#after_build'][] = 'configure_comment_form';
}

function configure_comment_form(&$form) {
  $form['und'][0]['format']['guidelines']['#access'] = FALSE;
  return $form;
}

понедельник, 5 декабря 2011 г.

Переопределить во views вывод страницы node/% только определенного тип материала

Решение:
Скопировать файлик node.tpl.php к себе в тему оформления, и там добавить в начало файлика следущее:


<?php if ($node->type=="product"): ?>
        <?php print views_embed_view('page_of_selling_item','page_1', $node->nid); ?>
<?php else: ?>
блаблабла - тут продолжается обычный файл.

Друпаловские табы и сообщения

По умолчанию не оформленные табы в друпале имеют ужасный вид. Чтобы их привести к красивым закругленно-бело-серым закладкам, нужно прописать следущее:


ul.tabs
{
    font-family: Tahoma, Arial, sans-serif;
    font-size: 11px;
    line-height: 17px;
    margin: 0 0 30px 0;
    padding: 0 0 0 4px;
}

ul.tabs li
{
    margin: 0 0 0 4px;
    padding: 0;
    border: 0;
}

ul.tabs li a:link,
ul.tabs li a:visited
{
    background: #F7F7F7;
    color: #BBBBBB;
    border: 1px solid #C5C5C5;
    border-top-left-radius: 3px; -moz-border-radius-topleft: 3px;
    border-top-right-radius: 3px; -moz-border-radius-topright: 3px;
    padding: 2px 9px 2px 10px;
    margin: 0;
}

ul.tabs li a:hover,
ul.tabs li a:active
{
    color: #5F5F5F;
    background: #F9F9F9;
}

ul.tabs li a.active:link,
ul.tabs li a.active:visited
{
    border-bottom-color: white;
    background: transparent;
    color: #515151;
}

ul.tabs.secondary
{
    position: relative;
    top: -10px;
}


Источник: http://xandeadx.ru/blog/drupal/252

Так же улучшаем вывод messages:

.messages {
        margin:15px 0px 15px 0px;
        font:bold 14px Arial,sans-serif;
        z-index:9999999;
}

.messages.status {
        background:#ccffcc;
        padding: 5px 5px 5px 15px;
        border: solid 1px green;
        color:black;
}

.messages.status a{
        color:#448844;
}

.messages.error {
        background:#ff8888;
        padding: 5px 5px 5px 15px;
        border: solid 1px red;
        color:black;
}

Добавление js-файла через drupal_add_js в template.tpl.php в Drupal 7

В 7й версии друпала добавление js-файла стало намного проще и производительнее.
Для этого надо использовать хук твоятема_preprocess_html(&$vars)

function adaptivetheme_mamaexpert_preprocess_html(&$vars) {
  if (drupal_is_front_page()) drupal_add_js(path_to_theme()  . '/js/frontpage-slideshow.js');
}

Для сравнения, в 6й версии необходимо было использовать хук твоятема_preprocess(&$vars, $hook), примерно так:
function твоятема_preprocess(&$vars, $hook) {
  if (drupal_is_front_page()) drupal_add_js(path_to_theme()  .