You are here

function tinypng_form_image_style_edit_form_alter in TinyPNG 8

Implements hook_form_FORM_ID_alter().

File

./tinypng.module, line 26
TinyPng module.

Code

function tinypng_form_image_style_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $config = \Drupal::config('tinypng.settings');
  if (empty($config
    ->get('api_key')) || empty($config
    ->get('image_action'))) {
    return;
  }

  /** @var \Drupal\image\Form\ImageStyleEditForm $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\image\Entity\ImageStyle $image_style */
  $image_style = $form_object
    ->getEntity();
  $form['tinypng_compress'] = [
    '#type' => 'checkbox',
    '#title' => t('Compress with TinyPNG', [], [
      'context' => 'tinypng',
    ]),
    '#default_value' => $image_style
      ->getThirdPartySetting('tinypng', 'tinypng_compress'),
    '#weight' => $form['effects']['#weight'] + 0.1,
  ];
  $form['#entity_builders'][] = 'tinypng_image_style_edit_form_builder';
}