public function ParagraphsFrontendUIAddBelow::buildForm in Paragraphs frontend ui 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ ParagraphsFrontendUIAddBelow.php, line 32
Class
- ParagraphsFrontendUIAddBelow
- Class CleanupUrlAliases.
Namespace
Drupal\paragraphs_frontend_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $paragraph = NULL) {
// Set the paragraph to the form state.
$form_state
->addBuildInfo('paragraph', $paragraph);
// Render the sets.
$sets = \Drupal::entityTypeManager()
->getListBuilder('paragraphs_library_item')
->load();
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder('paragraphs_library_item');
if (empty($sets)) {
$form['empty_text'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('No reusable paragraphs found.'),
];
}
$form['sets']['#attached']['library'][] = 'paragraphs_frontend_ui/paragraphs_frontend_ui.theme';
foreach ($sets as $set) {
$form['sets'][$set
->id()] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'add-paragraph-item',
],
],
];
$form['sets'][$set
->id()]['element'] = $view_builder
->view($set);
$form['sets'][$set
->id()]['add_set'] = [
'#type' => 'button',
'#name' => $set
->id() . '_add_set',
'#value' => $this
->t('Add'),
'#ajax' => [
'callback' => [
$this,
'addMoreAjax',
],
'effect' => 'fade',
],
];
}
$form['sets']['clearfix'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'clearfix',
],
],
];
$user = \Drupal::currentUser();
$form['add_set'] = [
'#type' => 'link',
'#title' => $this
->t('Add a new item'),
'#url' => Url::fromRoute('entity.paragraphs_library_item.add_form', [
'destination' => \Drupal::destination()
->get(),
]),
'#access' => $user
->hasPermission('create paragraph library item'),
];
return $form;
}