public function ImageAPIOptimizeProcessorFormBase::buildForm in Image Optimize (or ImageAPI Optimize) 4.x
Same name and namespace in other branches
- 8.3 src/Form/ImageAPIOptimizeProcessorFormBase.php \Drupal\imageapi_optimize\Form\ImageAPIOptimizeProcessorFormBase::buildForm()
- 8.2 src/Form/ImageAPIOptimizeProcessorFormBase.php \Drupal\imageapi_optimize\Form\ImageAPIOptimizeProcessorFormBase::buildForm()
Parameters
\Drupal\imageapi_optimize\ImageAPIOptimizePipelineInterface $imageapi_optimize_pipeline: The image optimize pipeline.
string $imageapi_optimize_processor: The image optimize processor ID.
Return value
array The form structure.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Overrides FormInterface::buildForm
2 calls to ImageAPIOptimizeProcessorFormBase::buildForm()
- ImageAPIOptimizeProcessorAddForm::buildForm in src/
Form/ ImageAPIOptimizeProcessorAddForm.php - Form constructor.
- ImageAPIOptimizeProcessorEditForm::buildForm in src/
Form/ ImageAPIOptimizeProcessorEditForm.php - Form constructor.
2 methods override ImageAPIOptimizeProcessorFormBase::buildForm()
- ImageAPIOptimizeProcessorAddForm::buildForm in src/
Form/ ImageAPIOptimizeProcessorAddForm.php - Form constructor.
- ImageAPIOptimizeProcessorEditForm::buildForm in src/
Form/ ImageAPIOptimizeProcessorEditForm.php - Form constructor.
File
- src/
Form/ ImageAPIOptimizeProcessorFormBase.php, line 52
Class
- ImageAPIOptimizeProcessorFormBase
- Provides a base form for image optimize processors.
Namespace
Drupal\imageapi_optimize\FormCode
public function buildForm(array $form, FormStateInterface $form_state, ImageAPIOptimizePipelineInterface $imageapi_optimize_pipeline = NULL, $imageapi_optimize_processor = NULL) {
$this->imageAPIOptimizePipeline = $imageapi_optimize_pipeline;
try {
$this->imageAPIOptimizeProcessor = $this
->prepareImageAPIOptimizeProcessor($imageapi_optimize_processor);
} catch (PluginNotFoundException $e) {
throw new NotFoundHttpException("Invalid processor id: '{$imageapi_optimize_processor}'.");
}
$request = $this
->getRequest();
if (!$this->imageAPIOptimizeProcessor instanceof ConfigurableImageAPIOptimizeProcessorInterface) {
throw new NotFoundHttpException();
}
$form['#attached']['library'][] = 'imageapi_optimize/admin';
$form['uuid'] = [
'#type' => 'value',
'#value' => $this->imageAPIOptimizeProcessor
->getUuid(),
];
$form['id'] = [
'#type' => 'value',
'#value' => $this->imageAPIOptimizeProcessor
->getPluginId(),
];
$form['data'] = [];
$subform_state = SubformState::createForSubform($form['data'], $form, $form_state);
$form['data'] = $this->imageAPIOptimizeProcessor
->buildConfigurationForm($form['data'], $subform_state);
$form['data']['#tree'] = TRUE;
// Check the URL for a weight, then the image optimize processor, otherwise use default.
$form['weight'] = [
'#type' => 'hidden',
'#value' => $request->query
->has('weight') ? (int) $request->query
->get('weight') : $this->imageAPIOptimizeProcessor
->getWeight(),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
];
$form['actions']['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#url' => $this->imageAPIOptimizePipeline
->toUrl('edit-form'),
'#attributes' => [
'class' => [
'button',
],
],
];
return $form;
}