New answers tagged

0

After working with JDev518 on this we discovered this was a permissions issue with paragraphs. Although this should have worked as is, we ended up installing Paragraph Type Permissions" and assigning specific permissions to create/edit/view the paragraph fields in question for anonymous. This "forced" the permission check to work and started including the ...


0

Refer below sample code function mymodule_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) { $field_name = $context['items']->getName(); $field = FieldConfig::loadByName('node', 'page', $field_name); if ($field) { $element['#prefix'] = 'hello world'; } }


1

Finally, I was able to resolve it by using the module handler "shs_term_data_response". Like below function YourModuleName_shs_term_data_response_alter(&$content, $context) { $termList = json_decode($content); $filteredList = array(); /..your logic to modify $termList and push it to new array.../ $content = json_encode($filteredList); } Hope ...


1

Actually, you will pass through your validateForm() method, whether you are using Ajax or not. In the validateForm(), you have to set the appropriate errors on your fields which do not validate. Then, as Charles Bamford stated, you need to handle the error management in your submit callback. So basically, you would end up with some kind of the following ...


0

i was able to get the value of surname from the Formstate, the form state had surname in surname field itself. public static function validate(array &$element, FormStateInterface $formState, array &$form) { $webformKey = $element['#webform_key']; $value = $formState->getValue($webformKey); $surname= $formState->...


0

If the validation callback is not being called, you can call it manually at the top of the ajax callback with $callback($form, $form_state). That said, the validation is probably being called, but the ajax callback doesn't know how to handle it. This is how I'm handling ajax callbacks on some forms I have. At the top of the ajax callback: $messages = \...


1

Not sure if it fits to your project. As a themer, I would create a form with Form Api in a custom module. The I would create a custom block for this form : src/Plugin/Block/HelloBlock.php See here for a example :https://www.drupal.org/docs/8/creating-custom-modules/creating-custom-blocks/create-a-custom-block I would then create a twig template for the ...


2

You must use the formBuilder, like this: $render = []; $render['elememt1'] = [ '#type' => 'markup', '#markup' => t('Test'), ]; $render['element2'] = \Drupal::formBuilder()->getForm('Drupal\MY_MODULE\Form\MyFormClass');// The destination of your form. return $render;


0

When you return a response instead of a Form API array public function buildForm(array $form, FormStateInterface $form_state, $extra = NULL) { ... return new JsonResponse($res); } the form is reduced to a request/response pattern of a controller. It is no longer possible to use it as a Drupal form.


2

It should be easily done like this: $form['submit']['#ajax'] = [ 'callback' => 'MYMODULE_submit_throbber_callback', 'progress' => [ 'type' => 'throbber', 'message' => NULL, ], ]; And then return $form in the callback;


0

Try overriding the #attached library on the managed file field: $form['sitemap'] = [ '#type' => 'managed_file', '#name' => 'sitemap', '#title' => t('Upload Site Map (xml)'), '#upload_location' => 's3://private/sitemap', '#field_suffix' => 'XML format supported', '#upload_validators' => [ '...


0

To summarize the question : I use an API where a SHA signature had to be sent along the form . That signature is calculated based on the other form inputs, so it had to be calculated after the user clicks the submit button and it had to be sent as a form field with POST method . In buildForm(), I have : $form['#action'] = 'https://url-webservices.fr/'; It ...


0

I found the solution here You can enable i18n_node module that is included in i18n module. Then: Go to edit the content type (admin/structure/types/manage/page). Open the 'Multilingual settings' tab. Check the 'Require language' checkbox. Done. Multilingual content must be installed at first and then in content type, Multilingual settings tab ...


0

Conditionals are still the answer, but turns out there's an easier way that doesn't involve getting the current path: function MYMODULE_form_commerce_checkout_flow_multistep_default_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form['#step_id'] == 'order_information') { Do stuff to the order information page form....


0

A. EntityFormBulder::getForm is just a shortcut for instantiating the form object, injecting the entity and building the render array. You can split this up: public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = []) { $form_object = $this->entityTypeManager->getFormObject($entity->...


0

Based on @DavidCzinege answer, a version that works for any form where the field appears and also for multivalued fields: use Drupal\Core\Render\Element; /** * Implements hook_form_alter(). */ function my_module_form_alter(&$form, &$form_state, $form_id) { if (!empty($form['field_file']['widget'])) { foreach (Element::children($form['...


1

You can do this directly inside hook_form_alter, like this: function security_question_form_user_register_form_alter(&$form, &$form_state) { $form['questions']['#weight'] = -47; } Then there is no need to create a custom function to do it. Another thing, you can't implement hook_form_FORM_ID_alter and then use $form_id inside that. You must ...


0

The problem - as Charles Bamford pointed out in the comments - is in the form_alter where the form id is checked. if($form['#id'] == 'default-form') The $form['#id'] changes each time the form is rebuilt when the Ajax callback happens. If you use above comparison, the code that attaches the Ajax callback will only be executed once the page is loaded, but ...


1

The submit button is defined in the base class and you can change it: public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form['actions']['submit']['#value'] = $this->t('Save my configuration'); ...


0

Module cancel_button provides that functionality.


2

Enable disable-refocus when adding the ajax callback: '#ajax' => [ 'callback' => [$this, 'friends_advance_search_results'], 'disable-refocus' => TRUE, ], See https://www.drupal.org/project/drupal/issues/2627788


0

$form['oneway']['from_date'] = array( '#title' => t('From Date'), '#type' => 'datetime', '#date_format' => 'Y-m-d', '#date_year_range' => '-80:0', '#required' => TRUE, '#attributes' => [ 'min' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'Y-m-d'), ], ); ...


0

I had to do something similar for having localized paragraphs for foreign languages with an option to hide the paragraph (until release date). The paragraph types I needed this I added a "Display Languages" checkboxes field with the options of All, supported languages, Hide. For example, you could create a paragraph and tick the DE option and the Hide ...


0

In Drupal 8 you can go to webform settings-> email/handler -> add email then select current user email address for To email.


0

This code should do it: function MYMODULE_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $view_ids = ['YOUR_VIEW_ID']; $view = $form_state->getStorage('view'); if ($form_id == 'views_exposed_form' && in_array($view['view']->id(), $view_ids)) { $form['field_new_used']['#...


0

I have solved it by using reduceStep() method to come back. $skipStep->reduceStep(); $form_state->set('multistep_controller', $skipStep); $form_state->setRebuild(); Hope this would help someone.


0

Needs to alter the form to unset form_id and form_build_id. In bellow code formid is the id of the form where you want to remove form_id and form_build_id. function mymodule_form_formid_alter(&$form, &$form_state, $form_id) { unset($form['form_build_id'], $form['form_id']); }


0

Here's the answer I was helped with. function MODULENAME_form_user_form_alter(&$form, $form_state, $form_id) { if (!\Drupal::currentUser()->hasPermission('administer users')) { $form['field_organization_name']['widget'][0]['value']['#attributes']['disabled'] = 'disabled'; $form['field_organization_reference']['widget'][0]['...


0

Try: function MYMODULE_form_user_form_alter(&$form, $form_state, $form_id) { // Your code... } Inspecting element, I see the form id is user-form, which needs to be translated to the machine-readable name user_form Otherwise, you can always do a standard HOOK_form_alter(): function MYMODULE_form_alter(&$form, $form_state, $form_id) { if ($...


Top 50 recent answers are included