You are here

function angular_media_form_alter in CKEditor Widgets 7

Implements hook_form_alter(). Add the Angular Media field for CKEditor.

File

./angular_media.module, line 484
Implementation of angular_media.module.

Code

function angular_media_form_alter(&$form, &$form_state, $form_id) {

  // @todo: other entity types...
  if (strpos($form_id, '_node_form') !== FALSE || $form_id === 'taxonomy_form_term') {
    $fieldName = 'media_ckeditor';
    $options = array(
      'hidden' => 1,
      'cardinality' => 9999,
      'fieldName' => $fieldName,
      'files' => array(),
      'cropRatio' => variable_get('angular_media_ckeditor_cropRatio', 'free'),
      'addlFieldName' => variable_get('angular_media_ckeditor_field_image', ''),
      'tabs' => variable_get('angular_media_ckeditor_tabs_image', array(
        'upload',
        'file',
        'flickr',
      )),
    );
    $path = angular_media_app_path();
    $form[$fieldName]['#attached'] = array(
      // @todo: make libraries_load work

      //'libraries_load' => array(

      //  array('angular_media', 'angular-media-app'),

      //)
      'js' => array(
        $path . 'js/libraries.min.js' => array(),
        $path . 'js/app.min.js' => array(),
        //$path . 'js/vendor/jcrop.min.js' => array('weight' => 10),
        drupal_get_path('module', 'angular_media') . '/js/angular-media.js' => array(),
      ),
      'css' => array(
        $path . 'css/app.min.css' => array(),
      ),
    );
    $element = array(
      '#type' => 'textfield',
      //'#title' => $instance['label'],

      //'#required' => $instance['required'],
      '#suffix' => theme('angular_media_app', array(
        'settings' => $options,
      )),
      '#attributes' => array(
        'style' => 'display:none',
      ),
    );
    $form[$fieldName] = $element;

    //@todo: this is hacky
    $form['#validate'][] = 'angular_media_field_widget_form_validate';
    $form['#submit'][] = 'angular_media_field_widget_form_validate';
    $form['angular_media_fields'] = isset($form['angular_media_fields']) ? $form['angular_media_fields'] : array(
      '#type' => 'value',
      '#value' => array(),
    );
    $form['angular_media_fields']['#value'][] = $fieldName;
  }
}