You are here

function atom_reference_field_settings in Scald: Media Management made easy 6

Implements hook_field_settings().

File

atom_reference/atom_reference.module, line 23
Defines a new field type, allowing to directly reference Scald Atoms from a node.

Code

function atom_reference_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $types = _scald_types();
      $options = array();
      foreach (_scald_types() as $name => $type) {
        $options[$name] = $type['title'];
      }
      $form = array();
      $form['referencable_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Atom types that can be referenced'),
        '#multiple' => TRUE,
        '#options' => $options,
        '#default_value' => $field['referencable_types'],
      );
      return $form;
    case 'save':
      return array(
        'referencable_types',
      );
    case 'database columns':
      $columns = array(
        'sid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
          'index' => TRUE,
        ),
      );
      return $columns;
    case 'views data':
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Relationship: add a relationship for related atom.
      $data[$table_alias][$field['field_name'] . '_sid']['relationship'] = array(
        'base' => 'scald_atoms',
        'field' => $db_info['columns']['sid']['column'],
        'handler' => 'content_handler_relationship',
        'label' => t($field['widget']['label']),
        'content_field_name' => $field['field_name'],
      );
      return $data;
  }
}