You are here

function blockreference_field in Block reference 6

Implementation of hook_field().

File

./blockreference.module, line 190
Defines a field type for referencing a block from a node.

Code

function blockreference_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      $refs = _blockreference_potential_references($field, TRUE);
      foreach ($items as $delta => $item) {
        if (is_array($item) && !empty($item['error_field'])) {
          $error_field = $item['error_field'];
          unset($item['error_field']);
          if (!empty($item['bid'])) {
            if (!in_array($item['bid'], array_keys($refs))) {
              form_set_error($error_field, t("%name : This block can't be referenced.", array(
                '%name' => t($field['widget']['label']),
              )));
            }
          }
        }
      }
      return $items;
  }
}