You are here

public function AutoOrientImageEffect::buildConfigurationForm in Image Effects 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageEffect/AutoOrientImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AutoOrientImageEffect::buildConfigurationForm()
  2. 8.2 src/Plugin/ImageEffect/AutoOrientImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AutoOrientImageEffect::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

src/Plugin/ImageEffect/AutoOrientImageEffect.php, line 94

Class

AutoOrientImageEffect
Automatically adjusts the orientation of an image resource.

Namespace

Drupal\image_effects\Plugin\ImageEffect

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  if (!extension_loaded('exif')) {

    // Issue a warning if the PHP EXIF extension is not enabled.
    drupal_set_message($this
      ->t('This image effect requires the PHP EXIF extension to be enabled to work properly.'), 'warning');
  }
  $form['info'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Information'),
  ];
  $form['info']['help'] = [
    '#markup' => $this
      ->t("<p>Certain cameras can embed <em>orientation</em> information into image\n        files when they save them. This information is embedded in an EXIF tag\n        and can be used to rotate images to their correct position for display.\n        <em>Not all cameras or images contain this information.</em>\n        This process is only useful for images that contain this information,\n        whereas for other images it is harmless.\n        </p>\n        <p>Although most modern browsers do support the orientation tag, the\n        information may get lost or become incorrect by other operations.\n        So, to support all browsers and prevent rotation errors, it is better to\n        start each image style with this effect.\n        </p>\n        <p>The expected/supported values are:<br/>\n        <strong>Tag</strong>: <code>0x0112  Orientation</code>\n        </p>\n        <ul>\n        <li>1 = Horizontal (normal)</li>\n        <li>3 = Rotate 180</li>\n        <li>6 = Rotate 90 CW</li>\n        <li>8 = Rotate 270 CW</li>\n        </ul>\n        <p>Wikipedia: <a href='https://en.wikipedia.org/wiki/Exchangeable_image_file_format'>Exchangeable image file format</a></p>\n      "),
  ];
  $form['scan_exif'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Scan image file'),
    '#description' => $this
      ->t('When selected, original image files supporting EXIF data (e.g. JPEG, TIFF) will be scanned to determine styled image orientation and dimensions. This slightly impacts performance, but allows to render more accurate HTML <kbd>&lt;img&gt;</kbd> tags.'),
    '#default_value' => $this->configuration['scan_exif'],
  ];
  return $form;
}