New answers tagged

0

If this only happens when a Text format is associated with a WYSIWYG profile, regardless of the format's Text filters or the Editor assigned to it, then it might be the Rich Text Editor doing this. Try using a non-breaking space (&nbsp;) as the anchor text: <a href="https://myfburl"><i class="fab fa-facebook-f "></i>&nbsp;</a>...


0

I figured it out, hope this helps anyone else out there. I added the following to my Adminimal Sub theme to add a class to the summary textarea: function adminimal_sub_form_alter(&$form, &$form_state, $form_id) { if (isset($form['#node']) && $form['#node']->type == 'article') { // Add class to body textarea for various content types. ...


0

You can use hook_node_access: Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a node. The second parameter for this hook is $op: $op: The operation to be performed. Possible values: "create" "delete" "update" "view" And the return values are: ...


0

Ok so here is another way to do it, if you dont want to do it with rules; <?php /** * Implements hook_form_FORM_ID_alter(). * * Alters the user registration form by adding a custom submit handler. */ function custom_user_insert(&$edit, $account, $category) { if (isset($account->is_new) && !empty($account->is_new)) { //...


0

In Drupal 8 you can just use the module: https://www.drupal.org/project/user_field_value


0

The Rules module will allow you create new OG node after saving a new user account. Just do the following: Create your rule and add an "After saving new user account" event to it In the action section, select create a new entity In the value section, select node In the Content type, select the "your group" Fill the title as you need; you can do this using ...


0

Late answer for anyone who comes across this. The cfrblock module, based on renderkit, allows to combine blocks and elements in any way you want, also supports conditional logic. I am not sure if this covers the specific requirement of the original question: The original question wants to insert block-1 into block-2. What I am proposing here allows to ...


0

Late answer for anyone who comes across this. The cfrblock module, based on renderkit, allows to combine blocks and elements in any way you want, also supports conditional logic. Follow the instructions on the module page: Install cfrblock, renderkit, cfrpreset. This involves some composer packages, you will find instructions on renderkit module page. Go ...


0

For Drupal 7 use arg() function and you are good to go. For Drupal 8 follow below procedure, Here's the example of accessing URL parameters and passing them to a TWIG template, I am considering you have already created your module and required files and suppose "/test?fn=admin" is your URL In Your .module file implement hook_theme and define variables and ...


6

You must do this in a hook_form_FORM_ID_alter(). You wouldn't use hook_form_alter() unless you are checking on a dynamic form ID. In this case it's better to use hook_form_FORM_ID_alter(). The reason for this, is that hook_form_alter() is called on every form render and hook_form_FORM_ID_alter() is only called when that specific form is being rendered. ...


4

You can do that by Implements hook_form_BASE_FORM_ID_alter but that would allow passing the step if the user enters any random string inside the coupon field. To avoid this confusion you need to use the form alter to make coupon field required and also add custom validation to check if the coupon is valid. if the coupon is not valid, then the user will ...


1

You need to have some sort of content assigned to the URL url1. The simplest way would be to create a new Basic page node and set its URL alias field to url1. By the way, what you are seeing now is the "page that is displayed when no other content matches the requested document" (Administration >> Configuration >> System >> Site ...


1

Found the fix (finally - at least in my case). Generating the View was exceeding the memory limit. I simply increased the allowed memory limit in my settings.php file by adding the following line to it: ini_set('memory_limit', '512M');


2

If all you want to know is whether the form is being loaded before or after a submit while debugging, then look at the array in $form_state['input']. If it is an empty array, then it is being loaded for the first time (before a submit). If it has elements then the form is being loaded after a submit. If you want to see if field values have been changed in a ...


0

Use the views_html_tags module to add tag in available HTML tags list. Add nid (Node ID) to view fields, put it on the top and hide it. Add class "node-[nid]" to field_heading. Add field 'field_background_color' to view fields and place it between 'nid' and 'field_heading' fields. Don't hide it. Rewrite it's output to: .node-[nid] { background-color: [...


0

In My case database read replica was pointed to another endpoint that was causing the same issue. Commenting or changing to correct one fixed the issue.


1

You can use hook_js_alter to replace your JS file (from parent theme) with the one in your child theme.


1

You can add other fields to your form as hiden, in the hook_form_alter for example add SKU field as hidden. $form['sky'] = [ '#type' => 'hidden', '#value' => YOUR_VALUE, ]; Hidden fields will submitted like others.


0

I know it's an old question, but for anybody looking for a way to do this argiepano's answer is not very clear. Found that their first solution works just fine, and actually that's how it's done by the code that does the importing in the CER admin UI: // Create the entity using the JSON string. $entity = entity_import('cer', '{JSON STRING HERE}'); // Now do ...


0

The field "field-seo-general" is a #container. The The Form API entry for container does not include #collapsed or #collapsible as properties. It seems that fieldset is the only element that can use the #collapsed and #collapsible properties. Change the #type for field-seo-general to fieldset to make it collapsible. If field-seo-general needs to be a ...


0

If you use pathauto module: You can use hook_pathauto_alias_alter like the following: /** * Implements hook_pathauto_alias_alter(). */ function YourModuleName_pathauto_alias_alter(&$alias, array &$context) { // Change tags here by your term name if ($context['module'] == 'taxonomy_term' && isset($context['type']) && $context['...


1

After going through all of your replies and a few internal discussions in my company, I have decided to modify the Quiz module's code by creating and applying a patch, quiz_notice_messages_in_result_screen.patch. As per the information provided by Alfred Armstrong's the said patch will be solely used for our company's internal purposes, so as to find a way ...


0

Using Views, you will need to use a contextual filter based on the year. For the exposed filter, I have utilized the settings for the date like so:


0

I think the assumption in your answer "I do know that modifying the code in a contrib module is not the best practice" is incorrect in this case, even though it's true in general. If all you want to do is fix the notices, then just fork the project and even pull in the upstream patches that fix these notices. The issues you note are almost certainly easy ...


0

The working htaccess rule that will do the Redirect is as follows. Redirect 301 "/sites/default/files/OLB Registration Guide.pdf" "/sites/default/files/downl_section/Online-Banking-Registration-Guide.pdf" This will only work if both the files exist in the system. If the first file does not exist then the rewrite rule that rewrites all urls that do not map ...


0

Drupal 8 Version: $query = \Drupal::entityQuery('node') ->addTag('debug') ->execute();


1

You can keep the field set to single choice, and use hook_webform_submission_render_alter() to display the values as if it was still a multi-select field. You can use the hook in a module or the template.php of a theme. If you are thinking about implementing it in a theme, keep in mind that the Webform Results view is displayed through the Administration ...


0

You could instead create a new component for the single choice option, and disable the multi-option one.


1

That function is just a wrapper for this function: https://api.drupal.org/api/views/views.module/function/views_set_current_view/7.x-3.x which will just return a reference to a static code cache. Conclusion: no view gets run, it's just grabbing a copy of what's already been created. In general, views is very efficient in such cases. But I'd tend to agree ...


0

I had this error appear rather suddenly on one of our Drupal 7 sites. Went through a lengthy verification process of other things listed, but in the end, all I did was flush my cache manually as described here. MySQL: TRUNCATE TABLE cache; TRUNCATE TABLE cache_block; TRUNCATE TABLE cache_bootstrap; TRUNCATE TABLE cache_field; TRUNCATE TABLE cache_filter; ...


0

I figured it out. The solution to this problem is so simple that i feel a bit embarrassed posting the solution. However, here it goes for those who may stumble upon it. This only needs to happen during the initial configuration and revert back once this step is completed (Based solely on my experience). Drupal cache for anonymous users needs to be disabled ...


0

You can use Features Module. Create another feature for menus. Push your new module to your server. Enabled it in the new server. drush en your_feature Revert your feature drush fr your_feature


1

Menu items are sore in the database. You are still able to export the menu using a contrib module. For Drupal 7 You can achieve that by using Menu Export/Import contrib module. For Drupal 8 You can achieve that by using Menu Import and Export. The module will give you the ability to exports the menu entity as config YAML and will be imported on ...


0

For somebody looking to find how to do this in Drupal 8 here is the corresponding question and answer How can I get the nid of a node from the page alias? use \Drupal\Core\Url; $alias = \Drupal::service('path.alias_manager')->getPathByAlias('/etapes-de-la-vie'); $params = Url::fromUri("internal:" . $alias)->getRouteParameters(); $entity_type = key($...


1

Use hook_theme() inside your theme's template.php file to set a custom template file (tpl.php) for the taxonomy add and edit forms. However, your theme needs to be set as the Administration Theme, even if Use the administration theme when editing or creating content is not checked. The taxonomy module implements only one form template file for the taxonomy ...


2

Menu items are saved in the DB, therefore you must update them using update hooks. Something like this should work: function MODULE_NAME_update_N() { $menu_link_id = 1; $menu_link = menu_link_load($menu_link_id); $menu_link['hidden'] = 0; menu_link_save($menu_link); }


1

It's simple. In fact, there is no need to add any relationship in the Views. Just create the taxonomy term view and add a filter criteria of Taxonomy term: Parent term. (see screenshot) Then set the value to be equal to ''. This will fetch you all the parent terms as they don't have any parent! ('')


0

It's hard to recommend something without more specifics. How are you imagining the way people can vote? Are they voting for their favorite player for that game, and can only vote for one player per game? Do they give "thumbs-up" to as many players as they want? Do they assign X out of 5 stars to a player? The Fivestar module is very popular, and has pretty ...


1

You can create your own module that adds a field formatter for the text_with_summary field type. At the bare minimum you will need to implement the following hooks: hook_field_formatter_info() for defining the formatter hook_field_formatter_view() for outputting the results hook_field_formatter_settings_form() for adding a form field to input the pattern ...


2

Yes profile_create() is deprecated. You should use profile2_create() instead. See the profile2.module file: /** * Deprecated. Use profile2_create(). */ function profile_create(array $values) { return new Profile($values); }


0

With the help of the Switch Page Theme module, you can change the template based on roles and pages.


1

There is no hook fired in delete of block, as you can see in the list of block hooks here block.api.php. There is a topic in Drupal forum here. I think the best way to handle this is by hook_form_alter something like. /** * Implements hook_form_alter(). */ function YourModule_form_alter(&$form, $form_state, $form_id) { if ($form_id == '...


1

There is two problems: You form method is GET so form submit action will be the actual path with the params like node/10?search_location=kathmandu&op=Search&form_build_id=form-s4JrAE91au_BWakeBLD7RUsktRTBXFCpJQrnHGiOjg8&form_token=ES2W0RDpLOnWZUsXOnP4f9gBmSXcYLvqhO9uy1ee4Vk&form_id=d7_exp_form The second one you set your action to '/buy/{...


0

In your case, you don't need to specify custom submit handler because if your form ID is mysimple_form, Drupal should use mysimple_form_submit as default form submission function. For more info see the https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7.x#submit_property


0

You can make use of Token authentication but be careful: From module description: Be careful with what paths you expose to Token Authentication, as it is effectively a very simple, very low security password mechanism. You can expose Administration pages through bad configuration. Install / enable Token authentication Module. Go to admin/config/services/...


-1

Drupal 8 update. Also valid. $nids = db_query("SELECT nid FROM node_field_data WHERE nid IN (:nids[]) AND status = 1", [ ':nids[]' => $nids ])->fetchCol();


0

This is working code on how to do this in Twig without contrib. You can change the '#style_name' parameter to play with making this dynamic for a multifield. {% for item in content.field_image['#items'] %} {% set image = { '#theme': 'image_style', '#style_name': 'medium', '#uri': item.entity.uri.value, '#alt': ...


0

There is also the mail_logger module


0

If the route for that path is, for example, track-new/%/%node or track-new/%user/%node, I would use the following code. if ($node = menu_get_object('node', 2)) { $content_type = $node->type; } If the route for that path is, for example, track-new/%/% or track-new/%user/%, I would use the following code. $nid = arg(2); if (!empty($nid) && ...


0

If you are asking as administrator of a Drupal site, you don't need to write PHP code to achieve what you described: Whenever it's a block you created from the UI, or it's a block implemented from a module, you can change for which content types the block is shown. On admin/structure/block, find the block you want to show only for some content types. (In ...


Top 50 recent answers are included