You are here

function geysir_get_add_first_paragraph_markup in Geysir 8

Get the 'Add first paragrah' link.

Parameters

Node $node: The parent node.

$field_name: The field name.

$field_wrapper_id: The wrapper in place for the field.

$field_label: The field label

Return value

mixed The markup of the link.

1 call to geysir_get_add_first_paragraph_markup()
geysir_preprocess_node in ./geysir.module
Implements hook_preprocess_HOOK().

File

./geysir.module, line 507
Geysir module file.

Code

function geysir_get_add_first_paragraph_markup(Node $node, $field_name, $field_wrapper_id, $field_label) {
  $links['add_before'] = [
    'title' => t('Start adding content to %field_label', [
      '%field_label' => $field_label,
    ]),
    'url' => Url::fromRoute('geysir.modal.add_form_first', [
      'parent_entity_type' => $node
        ->getEntityType()
        ->id(),
      'parent_entity_bundle' => $node
        ->bundle(),
      'parent_entity_revision' => $node
        ->getRevisionId() ? $node
        ->getRevisionId() : $node
        ->getLoadedRevisionId(),
      'field' => $field_name,
      'field_wrapper_id' => $field_wrapper_id,
      'delta' => 0,
      'position' => 'before',
      'js' => 'nojs',
    ]),
    'attributes' => [
      'class' => [
        'use-ajax',
        'geysir-button',
      ],
      'data-dialog-type' => 'modal',
      'title' => t('Start adding content to %field_label', [
        '%field_label' => $field_label,
      ]),
    ],
  ];
  $links_array = [
    '#theme' => 'links',
    '#links' => $links,
    '#attributes' => [
      'class' => [
        'geysir-field-paragraph-links',
        'geysir-field-paragraph-add-first',
        'links',
      ],
    ],
    '#attached' => [
      'library' => [
        'core/drupal.dialog.ajax',
        'geysir/geysir',
      ],
    ],
  ];
  return Drupal::service('renderer')
    ->render($links_array);
}