Endfor

/**
 * Endfor.
 */
<?php
for ($i = 1; $i <= 10; $i++): echo $i; endfor; ?>
/**
 * Classic syntax.
 */
<?php
for ($i = 1; $i <= 10; $i++){ echo $i; } ?>

Syntax with “endfor” used mostly in complex templates where easier to find “endfor” than “}”:

Advertisements

hook_entity_presave

/**
 * Implements hook_entity_presave().
 * @param $entity
 */
function hook_entity_presave($entity) {
  if (isset($entity->type) && $entity->type == 'estimate') {
    set_estimate($entity);
  }
}

hook_entity_presave() is run before the entity is saved. This applies for both the initial creation of an entity, and saving a edited entity.

In the example provided, I check the type of entity, before parsing $entity to another function.

hook_form_views_exposed_form_alter

/**
 * Implements hook_form_views_exposed_form_alter().
 * Set the default exposed filter value.
 * @param $form
 * @param $form_state
 */
function hook_form_views_exposed_form_alter(&$form, &$form_state) {
  if (!isset($form_state['input']['field_date_value_1']['value']['date'])) {
    $form_state['input']['field_date_value_1']['value']['date'] = date("Y-m", strtotime("+1 month"));
  }
}

hook_form_views_exposed_form_alter() is run before the form is rendered. It’s hook_form_alter(), but with the form_id of view_exposed_form.

In the example I provided, I have a date filter with the name of: field_date_value_1.

By default, the value of the filter is empty. I want to change that. The code checks whether the filter value is set. If not, it sets the filter date value to that of next month.