X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fimage%2Fsrc%2FForm%2FImageStyleEditForm.php;fp=web%2Fcore%2Fmodules%2Fimage%2Fsrc%2FForm%2FImageStyleEditForm.php;h=574d9145a8b954fc4a0fba4b6548103d0dbf6f64;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/image/src/Form/ImageStyleEditForm.php b/web/core/modules/image/src/Form/ImageStyleEditForm.php new file mode 100644 index 000000000..574d9145a --- /dev/null +++ b/web/core/modules/image/src/Form/ImageStyleEditForm.php @@ -0,0 +1,282 @@ +imageEffectManager = $image_effect_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager')->getStorage('image_style'), + $container->get('plugin.manager.image.effect') + ); + } + + /** + * {@inheritdoc} + */ + public function form(array $form, FormStateInterface $form_state) { + $user_input = $form_state->getUserInput(); + $form['#title'] = $this->t('Edit style %name', ['%name' => $this->entity->label()]); + $form['#tree'] = TRUE; + $form['#attached']['library'][] = 'image/admin'; + + // Show the thumbnail preview. + $preview_arguments = ['#theme' => 'image_style_preview', '#style' => $this->entity]; + $form['preview'] = [ + '#type' => 'item', + '#title' => $this->t('Preview'), + '#markup' => drupal_render($preview_arguments), + // Render preview above parent elements. + '#weight' => -5, + ]; + + // Build the list of existing image effects for this image style. + $form['effects'] = [ + '#type' => 'table', + '#header' => [ + $this->t('Effect'), + $this->t('Weight'), + $this->t('Operations'), + ], + '#tabledrag' => [ + [ + 'action' => 'order', + 'relationship' => 'sibling', + 'group' => 'image-effect-order-weight', + ], + ], + '#attributes' => [ + 'id' => 'image-style-effects', + ], + '#empty' => t('There are currently no effects in this style. Add one by selecting an option below.'), + // Render effects below parent elements. + '#weight' => 5, + ]; + foreach ($this->entity->getEffects() as $effect) { + $key = $effect->getUuid(); + $form['effects'][$key]['#attributes']['class'][] = 'draggable'; + $form['effects'][$key]['#weight'] = isset($user_input['effects']) ? $user_input['effects'][$key]['weight'] : NULL; + $form['effects'][$key]['effect'] = [ + '#tree' => FALSE, + 'data' => [ + 'label' => [ + '#plain_text' => $effect->label(), + ], + ], + ]; + + $summary = $effect->getSummary(); + + if (!empty($summary)) { + $summary['#prefix'] = ' '; + $form['effects'][$key]['effect']['data']['summary'] = $summary; + } + + $form['effects'][$key]['weight'] = [ + '#type' => 'weight', + '#title' => $this->t('Weight for @title', ['@title' => $effect->label()]), + '#title_display' => 'invisible', + '#default_value' => $effect->getWeight(), + '#attributes' => [ + 'class' => ['image-effect-order-weight'], + ], + ]; + + $links = []; + $is_configurable = $effect instanceof ConfigurableImageEffectInterface; + if ($is_configurable) { + $links['edit'] = [ + 'title' => $this->t('Edit'), + 'url' => Url::fromRoute('image.effect_edit_form', [ + 'image_style' => $this->entity->id(), + 'image_effect' => $key, + ]), + ]; + } + $links['delete'] = [ + 'title' => $this->t('Delete'), + 'url' => Url::fromRoute('image.effect_delete', [ + 'image_style' => $this->entity->id(), + 'image_effect' => $key, + ]), + ]; + $form['effects'][$key]['operations'] = [ + '#type' => 'operations', + '#links' => $links, + ]; + } + + // Build the new image effect addition form and add it to the effect list. + $new_effect_options = []; + $effects = $this->imageEffectManager->getDefinitions(); + uasort($effects, function ($a, $b) { + return strcasecmp($a['id'], $b['id']); + }); + foreach ($effects as $effect => $definition) { + $new_effect_options[$effect] = $definition['label']; + } + $form['effects']['new'] = [ + '#tree' => FALSE, + '#weight' => isset($user_input['weight']) ? $user_input['weight'] : NULL, + '#attributes' => ['class' => ['draggable']], + ]; + $form['effects']['new']['effect'] = [ + 'data' => [ + 'new' => [ + '#type' => 'select', + '#title' => $this->t('Effect'), + '#title_display' => 'invisible', + '#options' => $new_effect_options, + '#empty_option' => $this->t('Select a new effect'), + ], + [ + 'add' => [ + '#type' => 'submit', + '#value' => $this->t('Add'), + '#validate' => ['::effectValidate'], + '#submit' => ['::submitForm', '::effectSave'], + ], + ], + ], + '#prefix' => '