New answers tagged

0

The reason the template method was not working on my site was the result of a caching issue. To use a template file for the user profile form you can put this(or find the existing implementations of the hooks) in your template.php: function yourtheme_form_user_profile_form_alter(&$form, &$form_state, $form_id) { $form['#theme'] = '...


1

You can Show/Hide the status field using hook_form_alter like this: function MYMODULE_form_node_form_alter(&$form, &$form_state) { $node = $form_state['node']; if (!isset($node->nid) || isset($node->is_new)) { $form['YOUR_FIELD']['#access'] = FALSE; // Node is new! } else { $form['YOUR_FIELD']['#access'] = TRUE; // Node is not ...


0

Taxonomy is hierarchical by nature, you can create category/sub stuff in it. AFAIK, there is not any field widget as you describe in drupal core with taxonomy field. Maybe some contrib module (have a look at term_reference_fancytree ). You also may define your own and generate a field widget dedicated to taxonomy.


0

You could also try $form_state->getValues()['entity_field_1'] as getValues() will build an array of values with the field name as the key.


1

Why are you using field's attribute 'name' instead of it's machine name 'field_prenom'? If you check in 'kint' you would get the hierarchy of 'placeholder' attribute. You can update placeholder using form_alter only. Check the below example. $form['field_name']['widget'][0]['value']['#placeholder'] = 'Nom';


0

You can add custom submit handler to your Webform through hook_form_alter for inserting it's data into your custom table. To achieve it check the below example. use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Database\Database; function MODULE_NAME_form_alter(&$form, $form_state, $form_id){ if($form['#form_id'] == "YOUR_WEBFORM"){ $form['...


1

It's not clear what entity type you have. In the question you ask for the label of a content type, which would be the entity node, then the label field is title. In the question title it is a more general question about the label of an entity and in the code you redirect to a group_content entity route, which would suggest this is another entity type. In ...


0

If you are trying to update a node you can use setTitle(), like this: $entity->setTitle('My custom title'); For other entity types you can use: $entity->setLabel('My custom title'); I also see that you don't save the entity, make sure to save the entity after setting the title: $entity->save();


0

How about using hook_entity_presave? /** * Implements hook_entity_presave(). */ function MY_CUSTOM_MODULE_entity_presave(EntityInterface $entity) { $type = $entity->getEntityTypeId(); if ($type == 'node') { // Add more logic based on your needs. $entity->set('title', 'kkkkk'); } }


0

I'm facing the same problems so I create a Free API service that recognize disposable and temporary email address: Block Temporary Email Email Endpoint: GET https://block-temporary-email.com/check/email/example@simplemail.top JSON response: { "status": 200, "domain": "simplemail.top", "temporary": true, "dns": true, } This API is 100% free and ...


0

The last one should be correct if the form has a field called field_start_date. You fetch values from the form_state like this: $form_state['values']['FIELD_NAME']; To see which values are available in the form_state you can use the devel module to print the values from the form state using dpm($form_state['values']). UPDATE: You can't really use ...


0

If it is a custom variable, you should use $form_state->set('property_name', 'value') (instead of "$form_state->setValue(...)"). Example: public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // Update custom variable (in PHP "null + 1" equals one) $form_state->set('...


0

Don't forget to enable required services under /admin/config/services/rest: Enable REST resource "Webform Submit" Enable REST resource "Webform Elements" Enable REST resource "Webform Submission"


0

You can pass a FormattableMarkup element as #markup: $markup = new Drupal\Component\Render\FormattableMarkup("<p>Some string with <em>HTML markup</em></p>"); $form['TEST-Cloze'] = [ '#markup' => $markup, ]; Note that I didn't use the text from your example, as you would be better off using the Form API to build your elements. ...


0

If this was just content I would replace #markup with #prefix. It will automatically render without escaping your HTML. However, it seems like you don't just want to render this HTML. You actually want it to interact with the Drupal Forms API. As such, I would recommend that you parse the data you need from the source and construct the form element the ...


0

Sorry, I must have overlooked the way you built the form. Unless you make your values in the table row part of the form, you cannot submit them. I changed the row '#type' to a text field and added a default value, in that way you can now pass that along with your form. Try this: public function buildForm(array $form, FormStateInterface $form_state) { $...


0

I see two things that stand out to me: 1) Setting the '#name' attribute on the submit button. You should never do that. I've learned over the days that there is always a better way to do whatever you're trying to do when setting the #name attribute, and setting it causes some wonkiness. This may be why your form is not rebuilding. 2) You are rendering your ...


4

I think you cannot have a module hook executed the same hook implemented by a theme. If we look at the hook invoking code, we see that the theme hooks are invoked separately and after the module hooks. The best bet would be to remove it from the theme and put it in a module, or trying with #after_build. FormBuilder.php contains the following code. $this-&...


0

Old thread now, but I encountered a similar problem and ended up breaking apart the date field to solve it. The solution has been working well and opened up other opportunities across the site to select and search content by any date combination. My original question and answer is here: How to create a filter in Views for filtering dates by day, month, or ...


0

@jrockowitz suggested I look here; drupal.org/project/webform/issues/2783937 This solved my question. Thank you jrockowitz.


0

I think the problem is that you only return the another-field in the ajax callback. You probably have to make a wrapper for the submit and the another-field. So you willl have: $form['ajax_wrapper'] = array( 'submit' => array( // Submit button... ), 'another-field' => array( // Another field... ), ); And then return $form['...


1

This is not a Drupal question, but a general PHP question. If your site is running PHP7, you can use the new Throwable instead of the Exception public function approve_button_handler(array &$form, FormStateInterface $form_state){ $nid = $form_state->getValue('nid'); try { $terra_node = Node::load($nid); $...


0

In your ajax callback function write the code to disable button. like: public function ajax_function(array &$form, FormStateInterface $form_state) { $form['my_button']['#attributes']['disabled'] = true; return $form['my_button']; } Hope it helps!


Top 50 recent answers are included