Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function prepareImageEffect($image_effect)
 {
     $image_effect = $this->effectManager->createInstance($image_effect);
     // Set the initial weight so this effect comes last.
     $image_effect->setWeight(count($this->imageStyle->getEffects()));
     return $image_effect;
 }
Пример #2
0
 /**
  * Submit handler for image effect.
  */
 public function effectSave($form, &$form_state)
 {
     // Update image effect weights.
     if (!empty($form_state['values']['effects'])) {
         $this->updateEffectWeights($form_state['values']['effects']);
     }
     $this->entity->set('name', $form_state['values']['name']);
     $this->entity->set('label', $form_state['values']['label']);
     $status = parent::save($form, $form_state);
     if ($status == SAVED_UPDATED) {
         drupal_set_message($this->t('Changes to the style have been saved.'));
     }
     // Check if this field has any configuration options.
     $effect = $this->imageEffectManager->getDefinition($form_state['values']['new']);
     // Load the configuration form for this option.
     if (is_subclass_of($effect['class'], '\\Drupal\\image\\ConfigurableImageEffectInterface')) {
         $form_state['redirect_route'] = array('route_name' => 'image.effect_add_form', 'route_parameters' => array('image_style' => $this->entity->id(), 'image_effect' => $form_state['values']['new']), 'options' => array('query' => array('weight' => $form_state['values']['weight'])));
     } else {
         $effect = array('id' => $effect['id'], 'data' => array(), 'weight' => $form_state['values']['weight']);
         $effect_id = $this->entity->addImageEffect($effect);
         $this->entity->save();
         if (!empty($effect_id)) {
             drupal_set_message($this->t('The image effect was successfully applied.'));
         }
     }
 }
Пример #3
0
 /**
  * Submit handler for image effect.
  */
 public function effectSave($form, FormStateInterface $form_state)
 {
     $this->save($form, $form_state);
     // Check if this field has any configuration options.
     $effect = $this->imageEffectManager->getDefinition($form_state->getValue('new'));
     // Load the configuration form for this option.
     if (is_subclass_of($effect['class'], '\\Drupal\\image\\ConfigurableImageEffectInterface')) {
         $form_state->setRedirect('image.effect_add_form', array('image_style' => $this->entity->id(), 'image_effect' => $form_state->getValue('new')), array('query' => array('weight' => $form_state->getValue('weight'))));
     } else {
         $effect = array('id' => $effect['id'], 'data' => array(), 'weight' => $form_state->getValue('weight'));
         $effect_id = $this->entity->addImageEffect($effect);
         $this->entity->save();
         if (!empty($effect_id)) {
             drupal_set_message($this->t('The image effect was successfully applied.'));
         }
     }
 }
Пример #4
0
 /**
  * Asserts the effect processing of an image effect plugin.
  *
  * @param string $effect_name
  *   The name of the image effect to test.
  * @param array $data
  *   The data to pass to the image effect.
  *
  * @return bool
  *   TRUE if the assertion succeeded, FALSE otherwise.
  */
 protected function assertImageEffect($effect_name, array $data)
 {
     $effect = $this->manager->createInstance($effect_name, array('data' => $data));
     return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.');
 }