/**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $paragraphs_type = $this->entity;
     $status = $paragraphs_type->save();
     if ($status) {
         drupal_set_message($this->t('Saved the %label Paragraphs type.', array('%label' => $paragraphs_type->label())));
     } else {
         drupal_set_message($this->t('The %label Paragraphs type was not saved.', array('%label' => $paragraphs_type->label())));
     }
     if ($status == SAVED_NEW && \Drupal::moduleHandler()->moduleExists('field_ui') && ($route_info = FieldUI::getOverviewRouteInfo('paragraph', $paragraphs_type->id()))) {
         $form_state->setRedirectUrl($route_info);
     } else {
         $form_state->setRedirect('entity.paragraphs_type.collection');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $field_definitions = $this->getFieldDefinitions();
     $extra_fields = $this->getExtraFields();
     $form += array('#entity_type' => $this->entity->getTargetEntityTypeId(), '#bundle' => $this->entity->getTargetBundle(), '#fields' => array_keys($field_definitions), '#extra' => array_keys($extra_fields));
     if (empty($field_definitions) && empty($extra_fields) && ($route_info = FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()))) {
         drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', array(':link' => $route_info->toString())), 'warning');
         return $form;
     }
     $table = array('#type' => 'field_ui_table', '#header' => $this->getTableHeader(), '#regions' => $this->getRegions(), '#attributes' => array('class' => array('field-ui-overview'), 'id' => 'field-display-overview'), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'field-weight'), array('action' => 'match', 'relationship' => 'parent', 'group' => 'field-parent', 'subgroup' => 'field-parent', 'source' => 'field-name')));
     // Field rows.
     foreach ($field_definitions as $field_name => $field_definition) {
         $table[$field_name] = $this->buildFieldRow($field_definition, $form, $form_state);
     }
     // Non-field elements.
     foreach ($extra_fields as $field_id => $extra_field) {
         $table[$field_id] = $this->buildExtraFieldRow($field_id, $extra_field);
     }
     $form['fields'] = $table;
     // Custom display settings.
     if ($this->entity->getMode() == 'default') {
         // Only show the settings if there is at least one custom display mode.
         $display_mode_options = $this->getDisplayModeOptions();
         // Unset default option.
         unset($display_mode_options['default']);
         if ($display_mode_options) {
             $form['modes'] = array('#type' => 'details', '#title' => $this->t('Custom display settings'));
             // Prepare default values for the 'Custom display settings' checkboxes.
             $default = array();
             if ($enabled_displays = array_filter($this->getDisplayStatuses())) {
                 $default = array_keys(array_intersect_key($display_mode_options, $enabled_displays));
             }
             $form['modes']['display_modes_custom'] = array('#type' => 'checkboxes', '#title' => $this->t('Use custom display settings for the following @display_context modes', ['@display_context' => $this->displayContext]), '#options' => $display_mode_options, '#default_value' => $default);
             // Provide link to manage display modes.
             $form['modes']['display_modes_link'] = $this->getDisplayModesLink();
         }
     }
     // In overviews involving nested rows from contributed modules (i.e
     // field_group), the 'plugin type' selects can trigger a series of changes
     // in child rows. The #ajax behavior is therefore not attached directly to
     // the selects, but triggered by the client-side script through a hidden
     // #ajax 'Refresh' button. A hidden 'refresh_rows' input tracks the name of
     // affected rows.
     $form['refresh_rows'] = array('#type' => 'hidden');
     $form['refresh'] = array('#type' => 'submit', '#value' => $this->t('Refresh'), '#op' => 'refresh_table', '#submit' => array('::multistepSubmit'), '#ajax' => array('callback' => '::multistepAjax', 'wrapper' => 'field-display-overview-wrapper', 'effect' => 'fade', 'progress' => 'none'), '#attributes' => array('class' => array('visually-hidden')));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Save'));
     $form['#attached']['library'][] = 'field_ui/drupal.field_ui';
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $field)
 {
     if ($field->locked) {
         $row['class'] = array('menu-disabled');
         $row['data']['id'] = t('@field_name (Locked)', array('@field_name' => $field->name));
     } else {
         $row['data']['id'] = $field->name;
     }
     $field_type = $this->fieldTypes[$field->type];
     $row['data']['type'] = t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
     $usage = array();
     foreach ($field->getBundles() as $bundle) {
         if ($route_info = FieldUI::getOverviewRouteInfo($field->entity_type, $bundle)) {
             $usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field->entity_type][$bundle]['label'], $route_info);
         } else {
             $usage[] = $this->bundles[$field->entity_type][$bundle]['label'];
         }
     }
     $usage_escaped = '';
     $separator = '';
     foreach ($usage as $usage_item) {
         $usage_escaped .= $separator . SafeMarkup::escape($usage_item);
         $separator = ', ';
     }
     $row['data']['usage'] = SafeMarkup::set($usage_escaped);
     return $row;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_values = $form_state->getValues();
     $field_values = $form_values['field_storage'];
     // Save field cardinality.
     $cardinality = $field_values['cardinality'];
     $cardinality_number = $field_values['cardinality_number'];
     if ($cardinality === 'number') {
         $cardinality = $cardinality_number;
     }
     $field_values['cardinality'] = $cardinality;
     unset($field_values['container']);
     // Merge incoming form values into the existing field.
     $field_storage = $this->field->getFieldStorageDefinition();
     foreach ($field_values as $key => $value) {
         $field_storage->set($key, $value);
     }
     // Update the field.
     try {
         $field_storage->save();
         drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $this->field->label())));
         $request = $this->getRequest();
         if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
             $request->query->remove('destinations');
             $form_state->setRedirectUrl($next_destination);
         } else {
             $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->field->entity_type, $this->field->bundle));
         }
     } catch (\Exception $e) {
         drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $this->field->label(), '%message' => $e->getMessage())), 'error');
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $this->entity->save();
     drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->entity->getLabel())));
     $request = $this->getRequest();
     if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
         $request->query->remove('destinations');
         $form_state->setRedirectUrl($next_destination);
     } else {
         $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->bundle));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $field_storage)
 {
     if ($field_storage->isLocked()) {
         $row['class'] = array('menu-disabled');
         $row['data']['id'] = $this->t('@field_name (Locked)', array('@field_name' => $field_storage->getName()));
     } else {
         $row['data']['id'] = $field_storage->getName();
     }
     $field_type = $this->fieldTypes[$field_storage->getType()];
     $row['data']['type'] = $this->t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
     $usage = array();
     foreach ($field_storage->getBundles() as $bundle) {
         $entity_type_id = $field_storage->getTargetEntityTypeId();
         if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
             $usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
         } else {
             $usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
         }
     }
     $row['data']['usage']['data'] = ['#theme' => 'item_list', '#items' => $usage, '#context' => ['list_style' => 'comma-list']];
     return $row;
 }
Esempio n. 7
0
 /**
  * Adds a contextual tab to entities.
  *
  * @param RouteMatchInterface $route_match
  *
  * @return RedirectResponse
  */
 public function contextualTab(RouteMatchInterface $route_match)
 {
     $parameter_name = $route_match->getRouteObject()->getOption('_ds_entity_type_id');
     $entity = $route_match->getParameter($parameter_name);
     $entity_type_id = $entity->getEntityTypeId();
     $destination = $entity->toUrl();
     if (!empty($entity->ds_switch->value)) {
         $view_mode = $entity->ds_switch->value;
     } else {
         $view_mode = 'full';
     }
     // Get the manage display URI.
     $route = FieldUI::getOverviewRouteInfo($entity_type_id, $entity->bundle());
     /** @var $entity_display EntityDisplayBase */
     $entity_display = EntityViewDisplay::load($entity_type_id . '.' . $entity->bundle() . '.' . $view_mode);
     $route_parameters = $route->getRouteParameters();
     if ($entity_display && $entity_display->getThirdPartySetting('ds', 'layout')) {
         $route_parameters['view_mode_name'] = $view_mode;
         $admin_route_name = "entity.entity_view_display.{$entity_type_id}.view_mode";
     } else {
         $admin_route_name = "entity.entity_view_display.{$entity_type_id}.default";
     }
     $route->setOption('query', array('destination' => $destination->toString()));
     $url = new Url($admin_route_name, $route_parameters, $route->getOptions());
     return new RedirectResponse($url->toString());
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Handle the default value.
     $default_value = array();
     if (isset($form['field']['default_value'])) {
         $items = $form['#entity']->get($this->field->getName());
         $default_value = $items->defaultValuesFormSubmit($form['field']['default_value'], $form, $form_state);
     }
     $this->field->default_value = $default_value;
     // Merge incoming values into the field.
     foreach ($form_state->getValue('field') as $key => $value) {
         $this->field->set($key, $value);
     }
     $this->field->save();
     drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->field->getLabel())));
     $request = $this->getRequest();
     if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
         $request->query->remove('destinations');
         $form_state->setRedirectUrl($next_destination);
     } else {
         $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->field->entity_type, $this->field->bundle));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $field_label = $form_state->get('field_config')->label();
     try {
         $this->entity->save();
         drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $field_label)));
         $request = $this->getRequest();
         if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
             $request->query->remove('destinations');
             $form_state->setRedirectUrl($next_destination);
         } else {
             $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($form_state->get('entity_type_id'), $form_state->get('bundle')));
         }
     } catch (\Exception $e) {
         drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $field_label, '%message' => $e->getMessage())), 'error');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getCancelUrl()
 {
     return FieldUI::getOverviewRouteInfo($this->entity->entity_type, $this->entity->bundle);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function getCancelUrl()
 {
     return FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle());
 }
Esempio n. 12
0
 /**
  * Form submission handler to redirect to Manage fields page of Field UI.
  */
 public function redirectToFieldUI(array $form, FormStateInterface $form_state)
 {
     if ($form_state->getTriggeringElement()['#parents'][0] === 'save_continue' && ($route_info = FieldUI::getOverviewRouteInfo('profile', $this->entity->id()))) {
         $form_state->setRedirectUrl($route_info);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $mode = 'default')
 {
     parent::buildForm($form, $form_state, $entity_type_id, $bundle);
     $this->mode = $mode;
     $field_definitions = $this->getFieldDefinitions();
     $extra_fields = $this->getExtraFields();
     $entity_display = $this->getEntityDisplay($this->mode);
     $form += array('#entity_type' => $this->entity_type, '#bundle' => $this->bundle, '#mode' => $this->mode, '#fields' => array_keys($field_definitions), '#extra' => array_keys($extra_fields));
     if (empty($field_definitions) && empty($extra_fields) && ($route_info = FieldUI::getOverviewRouteInfo($this->entity_type, $this->bundle))) {
         drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => $route_info->toString())), 'warning');
         return $form;
     }
     $table = array('#type' => 'field_ui_table', '#pre_render' => array(array($this, 'tablePreRender')), '#tree' => TRUE, '#header' => $this->getTableHeader(), '#regions' => $this->getRegions(), '#attributes' => array('class' => array('field-ui-overview'), 'id' => 'field-display-overview'), '#prefix' => '<div id="field-display-overview-wrapper">', '#suffix' => '</div>', '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'field-weight'), array('action' => 'match', 'relationship' => 'parent', 'group' => 'field-parent', 'subgroup' => 'field-parent', 'source' => 'field-name')));
     // Field rows.
     foreach ($field_definitions as $field_name => $field_definition) {
         $table[$field_name] = $this->buildFieldRow($field_definition, $entity_display, $form, $form_state);
     }
     // Non-field elements.
     foreach ($extra_fields as $field_id => $extra_field) {
         $table[$field_id] = $this->buildExtraFieldRow($field_id, $extra_field, $entity_display);
     }
     $form['fields'] = $table;
     // Custom display settings.
     if ($this->mode == 'default') {
         // Only show the settings if there is at least one custom display mode.
         if ($display_modes = $this->getDisplayModes()) {
             $form['modes'] = array('#type' => 'details', '#title' => $this->t('Custom display settings'));
             // Collect options and default values for the 'Custom display settings'
             // checkboxes.
             $options = array();
             $default = array();
             $display_statuses = $this->getDisplayStatuses();
             foreach ($display_modes as $mode_name => $mode_info) {
                 $options[$mode_name] = $mode_info['label'];
                 if (!empty($display_statuses[$mode_name])) {
                     $default[] = $mode_name;
                 }
             }
             $form['modes']['display_modes_custom'] = array('#type' => 'checkboxes', '#title' => $this->t('Use custom display settings for the following modes'), '#options' => $options, '#default_value' => $default);
         }
     }
     // In overviews involving nested rows from contributed modules (i.e
     // field_group), the 'plugin type' selects can trigger a series of changes
     // in child rows. The #ajax behavior is therefore not attached directly to
     // the selects, but triggered by the client-side script through a hidden
     // #ajax 'Refresh' button. A hidden 'refresh_rows' input tracks the name of
     // affected rows.
     $form['refresh_rows'] = array('#type' => 'hidden');
     $form['refresh'] = array('#type' => 'submit', '#value' => $this->t('Refresh'), '#op' => 'refresh_table', '#submit' => array(array($this, 'multistepSubmit')), '#ajax' => array('callback' => array($this, 'multistepAjax'), 'wrapper' => 'field-display-overview-wrapper', 'effect' => 'fade', 'progress' => 'none'), '#attributes' => array('class' => array('visually-hidden')));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Save'));
     $form['#attached']['library'][] = 'field_ui/drupal.field_ui';
     return $form;
 }
Esempio n. 14
0
  /**
   * Adds a contextual tab to entities.
   */
  public function contextualTab($entity_type, $entity_id) {
    /** @var $entity EntityInterface */
    $entity = entity_load($entity_type, $entity_id);
    $destination = $entity->urlInfo();

    if (!empty($entity->ds_switch->value)) {
      $view_mode = $entity->ds_switch->value;
    }
    else {
      $view_mode = 'full';
    }

    // Get the manage display URI.
    $route = FieldUI::getOverviewRouteInfo($entity_type, $entity->bundle());

    /** @var $entity_display EntityDisplayBase */
    $entity_display = entity_get_display($entity_type, $entity->bundle(), $view_mode);

    $route_parameters = $route->getRouteParameters();
    if ($entity_display->getThirdPartySetting('ds', 'layout')) {
      $route_parameters['view_mode_name'] = $view_mode;
      $admin_route_name = "entity.entity_view_display.$entity_type.view_mode";
    }
    else {
      $admin_route_name = "entity.entity_view_display.$entity_type.default";
    }
    $route->setOption('query', array('destination' => $destination->toString()));

    $url = new Url($admin_route_name, $route_parameters, $route->getOptions());

    return new RedirectResponse($url->toString());
  }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // Handle the default value.
     $default_value = array();
     if (isset($form['instance']['default_value'])) {
         $items = $form['#entity']->get($this->instance->getName());
         $default_value = $items->defaultValuesFormSubmit($form['instance']['default_value'], $form, $form_state);
     }
     $this->instance->default_value = $default_value;
     // Merge incoming values into the instance.
     foreach ($form_state['values']['instance'] as $key => $value) {
         $this->instance->{$key} = $value;
     }
     $this->instance->save();
     drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->instance->getLabel())));
     $request = $this->getRequest();
     if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
         $request->query->remove('destinations');
         if (isset($next_destination['route_name'])) {
             $form_state['redirect_route'] = $next_destination;
         } else {
             $form_state['redirect'] = $next_destination;
         }
     } else {
         $form_state['redirect_route'] = FieldUI::getOverviewRouteInfo($this->instance->entity_type, $this->instance->bundle);
     }
 }