You are here

public static function MinisiteWidget::process in Mini site 8

Form API callback: Processes a file_generic field element.

Expands the file_generic type to include the description and display fields.

This method is assigned as a #process callback in formElement() method.

Overrides FileWidget::process

File

src/Plugin/Field/FieldWidget/MinisiteWidget.php, line 75

Class

MinisiteWidget
Plugin implementation of the 'minisite_default' widget.

Namespace

Drupal\minisite\Plugin\Field\FieldWidget

Code

public static function process($element, FormStateInterface $form_state, $form) {
  $item = $element['#value'];
  $item['fids'] = $element['fids']['#value'];
  $element['#theme'] = 'minisite_widget';
  $description = t("Use the current page's URL (defined in URL path settings) as the mini-site base URL, so the mini-site seamlessly displays the page's URL path pre-fix.<br/>\n      For example, if the alias of the page is <code>/my-page-alias</code> and the top directory in uploaded ZIP named <code>mysite</code>, the final URL will resolve to <code>@url</code>.<br/>\n      Note that this will rewrite relative links within uploaded pages. See @help for more information about URL rewrite.", [
    '@url' => Url::fromUserInput('/my-page-alias/mysite/index.html', [
      'absolute' => TRUE,
    ])
      ->toString(),
    '@help' => Link::fromTextAndUrl(t('Minisite help'), Url::fromUri('base:/admin/help/minisite'))
      ->toString(),
  ]);

  // Add the additional fields.
  $element['options']['alias_status'] = [
    '#type' => 'checkbox',
    '#title' => t('Use URL alias'),
    '#default_value' => isset($item['options']['alias_status']) ? $item['options']['alias_status'] : FALSE,
    '#description' => $description,
    '#weight' => -11,
    '#access' => (bool) $item['fids'],
  ];
  return parent::process($element, $form_state, $form);
}