You are here

function file_style_form in Styles 7

Same name and namespace in other branches
  1. 7.2 contrib/file_styles/file_styles.admin.inc \file_style_form()

Form builder; Edit a file style name and effects order.

Parameters

$form_state: An associative array containing the current state of the form.

$style: An file style array.

See also

file_style_form_submit()

file_style_name_validate()

1 string reference to 'file_style_form'
xfile_styles_menu in contrib/file_styles/file_styles.module
Implement hook_menu().

File

contrib/file_styles/file_styles.admin.inc, line 89
Administrative page callbacks for the File: Styles module.

Code

function file_style_form($form, &$form_state, $file_style) {
  $title = t('Edit %name style', array(
    '%name' => $file_style['name'],
  ));
  drupal_set_title($title, PASS_THROUGH);

  // Adjust this form for styles that must be overridden to edit.
  $editable = (bool) ($file_style['storage'] & IMAGE_STORAGE_EDITABLE);
  if (!$editable && empty($form_state['input'])) {
    drupal_set_message(t('This file style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning');
  }
  $form_state['file_style'] = $file_style;
  $form['#tree'] = TRUE;
  $form['#attached']['css'][drupal_get_path('module', 'file') . '/file.admin.css'] = array(
    'preprocess' => FALSE,
  );
  $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array(
    'preprocess' => FALSE,
  );

  //   // Show the thumbnail preview.
  //   $form['preview'] = array(
  //     '#type' => 'item',
  //     '#title' => t('Preview'),
  //     '#markup' => theme('file_style_preview', array('style' => $style)),
  //   );
  // Allow the name of the style to be changed, unless this style is
  // provided by a module's hook_default_file_styles().
  if ($file_style['storage'] & IMAGE_STORAGE_MODULE) {
    $form['name'] = array(
      '#type' => 'item',
      '#title' => t('File style name'),
      '#markup' => $file_style['name'],
      '#description' => t('This file style is being provided by %module module and may not be renamed.', array(
        '%module' => $style['module'],
      )),
    );
  }
  else {
    $form['name'] = array(
      '#type' => 'textfield',
      '#size' => '64',
      '#title' => t('File style name'),
      '#default_value' => $file_style['name'],
      '#description' => t('The name is used in URLs for generated file. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
      '#element_validate' => array(
        'file_style_name_validate',
      ),
      '#required' => TRUE,
    );
  }

  // Build the list of existing file effects for this file style.
  $form['effects'] = array(
    '#theme' => 'file_style_effects',
  );

  //   foreach ($style['effects'] as $meid => $effect) {
  //     $form['effects'][$meid]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$meid]['weight'] : NULL;
  //     $form['effects'][$meid]['label'] = array(
  //       '#markup' => $effect['label'],
  //     );
  //     $form['effects'][$meid]['summary'] = array(
  //       '#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '',
  //     );
  //     $form['effects'][$meid]['weight'] = array(
  //       '#type' => 'weight',
  //       '#default_value' => $effect['weight'],
  //       '#access' => $editable,
  //     );
  //     $form['effects'][$meid]['configure'] = array(
  //       '#type' => 'link',
  //       '#title' => t('edit'),
  //       '#href' => 'admin/config/file/file-styles/edit/' . $style['name'] . '/effects/' . $effect['meid'],
  //       '#access' => $editable && isset($effect['form callback']),
  //     );
  //     $form['effects'][$meid]['remove'] = array(
  //       '#type' => 'link',
  //       '#title' => t('delete'),
  //       '#href' => 'admin/config/file/file-styles/edit/' . $style['name'] . '/effects/' . $effect['meid'] . '/delete',
  //       '#access' => $editable,
  //     );
  //   }
  $form['effects']['tabs'] = array(
    '#type' => 'vertical_tabs',
  );

  // Build the new file effect addition form and add it to the effect list.
  foreach (file_effect_definitions() as $definition_name => $definition) {
    $form['effects']['tabs'][$definition_name] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#title' => check_plain($definition['label']),
      '#description' => t('@label will be applied to the following:<br />Streams: %streams<br />File types: %types', array(
        '@label' => $definition['label'],
        '%streams' => implode(', ', $definition['streams']),
        '%types' => implode(', ', $definition['mimetypes']),
      )),
    );
    $new_effect_options = array(
      ' ' => t('Select a file style to apply'),
    );
    foreach ($definition['styles'] as $style_name => $style) {
      $effects = array();
      foreach ($style['effects'] as $effect) {
        $data = array();
        foreach ($effect['data'] as $type => $value) {
          $data[] = t('@type = @value', array(
            '@type' => $type,
            '@value' => $value,
          ));
        }
        $effects[] = t('@effect: (@data)', array(
          '@effect' => $effect['label'],
          '@data' => implode(', ', $data),
        ));
      }
      $new_effect_options[$style_name] = t('@name - %effects', array(
        '@name' => $style['name'],
        '%effects' => implode('; ', $effects),
      ));

      // check_plain($style['name'] . ' ' . implode(', ', $effects));
    }
    $form['effects']['tabs'][$definition_name]['new'] = array(
      '#type' => 'radios',
      '#title' => t('Please select a style from the following options:'),
      '#options' => $new_effect_options,
      '#default_value' => isset($file_style['styles'][$definition_name]) ? $file_style['styles'][$definition_name] : ' ',
    );
    if (isset($definition['add-new-link'])) {
      $form['effects']['tabs'][$definition_name]['new']['#description'] = filter_xss($definition['add-new-link']);
    }
    if (isset($definition['preview-theme'])) {

      // theme_image_style_preview is not properly registered.
      module_load_include('inc', 'image', 'image.admin');

      // Show the thumbnail preview.
      $form['effects']['tabs'][$definition_name]['preview'] = array(
        '#type' => 'item',
        '#title' => t('Preview'),
        '#markup' => theme($definition['preview-theme'], array(
          'style' => $definition['styles']['thumbnail'],
        )),
      );
    }

    //     $form['effects']['tabs'][$definition_name]['weight'] = array(
    //       '#type' => 'weight',
    //       '#default_value' => count($form['effects']['tabs'][$definition_name]) - 1,
    //     );
  }

  //   $new_effect_options = array('' => t('Select a new effect'));
  //   foreach (file_effect_definitions() as $effect => $definition) {
  //     $new_effect_options[$effect] = check_plain($definition['name']);
  //   }
  //   $form['effects']['new'] = array(
  //     '#tree' => FALSE,
  //     '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
  //     '#access' => $editable,
  //   );
  //   $form['effects']['new']['new'] = array(
  //     '#type' => 'radios',
  //     '#options' => $new_effect_options,
  //   );
  //   $form['effects']['new']['add'] = array(
  //     '#type' => 'submit',
  //     '#value' => t('Add'),
  //     '#validate' => array('file_style_form_add_validate'),
  //     '#submit' => array('file_style_form_submit', 'file_style_form_add_submit'),
  //   );
  // Show the Override or Submit button for this style.
  $form['override'] = array(
    '#type' => 'submit',
    '#value' => t('Override defaults'),
    '#validate' => array(),
    '#submit' => array(
      'file_style_form_override_submit',
    ),
    '#access' => !$editable,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update style'),
    '#access' => $editable,
  );
  return $form;
}