public function NodeTypePreviewImageForm::getForm in Acquia Content Hub 8
Get Form.
Parameters
string $node_type: Node Type.
Return value
array Acquia Content Hub preview image Form.
File
- src/
Form/ NodeTypePreviewImageForm.php, line 94
Class
- NodeTypePreviewImageForm
- Defines a form that alters node type form to add a preview image form.
Namespace
Drupal\acquia_contenthub\FormCode
public function getForm($node_type) {
$form = [
'#title' => $this
->t('Acquia Content Hub'),
'#type' => 'details',
'#tree' => TRUE,
'#group' => 'additional_settings',
];
// Find image fields.
$this
->collectImageFields('node', $node_type);
if (empty($this->imageFields)) {
$form['no_image_field'] = [
'#type' => 'markup',
'#markup' => '<div>' . $this
->t('This content type has no image field yet.') . '</div>',
];
return $form;
}
// Find image styles.
$image_styles = image_style_options(FALSE);
// If the default option is not in the system, offer to create and use the
// Acquia Content Hub default style.
if (!isset($image_styles[self::PREVIEW_IMAGE_DEFAULT_KEY])) {
$image_styles = [
self::PREVIEW_IMAGE_ADD_DEFAULT_KEY => $this
->t('Acquia Content Hub Preview Image (150×150)'),
] + $image_styles;
}
// Obtaining preview image field and style from the configuration entity.
$preview_image_field = $this->contenthubEntityConfig
->getPreviewImageField($node_type);
$preview_image_style = $this->contenthubEntityConfig
->getPreviewImageStyle($node_type);
// Building the form.
$form['field'] = [
'#type' => 'select',
'#title' => $this
->t("Select content type's preview image."),
'#options' => $this->imageFields,
'#default_value' => isset($preview_image_field) ? $preview_image_field : '',
'#empty_option' => $this
->t('None'),
'#empty_value' => '',
];
$form['style'] = [
'#type' => 'select',
'#title' => $this
->t("Select the preview image's style."),
'#options' => $image_styles,
'#default_value' => isset($preview_image_style) ? $preview_image_style : '',
'#empty_option' => $this
->t('None'),
'#empty_value' => '',
'#states' => [
'visible' => [
':input[name="acquia_contenthub[field]"]' => [
'!value' => '',
],
],
],
];
return $form;
}