You are here

function _manualcrop_attach_dependencies in Manual Crop 7

Attach the required croptool dependencies (files and settings).

Parameters

$element: The form element.

$form_state,: The form state array.

$js_identifier: Unique javascript crop settings identifier.

$settings: Widget settings.

1 call to _manualcrop_attach_dependencies()
manualcrop_croptool_process in ./manualcrop.helpers.inc
Add a croptool to the form element. This extends the FAPI widget or simply adds a new form item to enable cropping in a regular form.

File

./manualcrop.helpers.inc, line 313
Helper functions for the Manual Crop module.

Code

function _manualcrop_attach_dependencies(&$element, $form_state, $js_identifier, $settings = array()) {

  // Attach the required files.
  _manualcrop_attach_files($element);
  $added[$js_identifier] = $form_state['rebuild'];

  // Generate image style settings.
  $styles =& drupal_static(__FUNCTION__);
  if (!is_array($styles)) {
    $styles = array();
    foreach (manualcrop_styles_with_crop() as $style_name => $data) {
      $styles[$style_name] = array(
        'effect' => $data['effect']['name'],
        'data' => $data['effect']['data'],
        'label' => $data['label'],
      );
    }
  }

  // Attach the element settings.
  $element['#attached']['js'][] = array(
    'data' => array(
      'manualcrop' => array(
        'styles' => $styles,
        'elements' => array(
          $js_identifier => array(
            'keyboard' => !empty($settings['manualcrop_keyboard']),
            'required' => manualcrop_instance_required_styles($settings),
            'instantCrop' => !empty($settings['manualcrop_instant_crop']),
            'defaultCropArea' => !empty($settings['manualcrop_default_crop_area']),
            'maximizeDefaultCropArea' => !empty($settings['manualcrop_maximize_default_crop_area']),
          ),
        ),
      ),
    ),
    'type' => 'setting',
  );
}