You are here

public static function ImageCrop::getCropFormElement in Image Widget Crop 8

Same name and namespace in other branches
  1. 8.2 src/Element/ImageCrop.php \Drupal\image_widget_crop\Element\ImageCrop::getCropFormElement()

Inject crop elements into the form.

Parameters

array $element: All form elements.

string $element_wrapper_name: Name of element contains all crop properties.

array $original_properties: All properties calculate for apply to.

bool $edit: Context of this form.

string $crop_type_id: The id of the current crop.

Return value

array|null Populate all crop elements into the form.

1 call to ImageCrop::getCropFormElement()
ImageCrop::processCrop in src/Element/ImageCrop.php
Render API callback: Expands the image_crop element type.

File

src/Element/ImageCrop.php, line 269

Class

ImageCrop
Provides a form element for crop.

Namespace

Drupal\image_widget_crop\Element

Code

public static function getCropFormElement(array &$element, $element_wrapper_name, array $original_properties, $edit, $crop_type_id) {
  $crop_properties = self::getCropFormProperties($original_properties, $edit);

  // Generate all coordinate elements into the form when process is active.
  foreach ($crop_properties as $property => $value) {
    $crop_element =& $element['crop_wrapper'][$crop_type_id][$element_wrapper_name]['values'][$property];
    $value_property = self::getCropFormPropertyValue($element, $crop_type_id, $edit, $value['value'], $property);
    $crop_element = [
      '#type' => 'hidden',
      '#attributes' => [
        'class' => [
          "crop-{$property}",
        ],
      ],
      '#crop_type' => $crop_type_id,
      '#element_name' => $property,
      '#default_value' => $value_property,
    ];
    if ($property == 'height' || $property == 'width') {
      $crop_element['#element_validate'] = [
        [
          static::class,
          'validateHardLimit',
        ],
      ];
    }
  }
  return $element;
}