Profile2 regpath move account email field, into profile2 form and handle submit

1 month 3 weeks ago

I have a profile2 regpath displaying my profile2 form, and the system default account registration form below it. I need to move the account email field up into the container with the profile2 fields.

I have altered the form and moved the account mail field from the account form, into the profile form, and I have created an additional validation handler to try insert the mail value into the $form_state value so the user_account_form_validate() doesn't choke on a missing ['mail'] index:

function si_student_form_user_register_form_alter(&$form, &$form_state, $form_id) { global $user; // remove fieldgroups and tabs for anonymous users, e.g. /student/register if($user->uid == 0) { // move email field from account to below profile2 name fields $email = $form['account']['mail']; unset($form['account']['mail']); // add email to profile $form['profile_student']['mail'] = $email; // change weights $form['profile_student']['mail']['#weight'] = 3; // custom validation handler to inject mail value into // correct place in $form_state['values'] array $form['#validate'][] = '_si_student_register_anonymous_validate'; //dpm($form); } } function _si_student_register_anonymous_validate($form, &$form_state) { $form_state['values']['mail'] = $form_state['values']['profile_student']['mail']; }

However this isn't working, and I get the following:

Any ideas? I'm not sure I'm taking the right approach here. Thanks

davewilly

How do I fix this commerce_auction_node_presave error message?

1 month 3 weeks ago

I am working on a reverse auction for our youth group. I'm using D7 with the commerce_auction module. I ran into the error below when setting up the content type for the auction:

Notice: Undefined offset: 0 in commerce_auction_node_presave() (line 260 of /public_html/catz/sites/all/modules/commerce_auction/commerce_auction.module). EntityMalformedException: Missing bundle property on entity of type commerce_product. in entity_extract_ids() (line 7697 of /public_html/catz/includes/common.inc).

for the first notice, line 260 contains this: $product_reference = $product_reference[0];

Does anyone know how to fix this error? There's not a lot of commenting as yet on this auction module, so I can't find a solution.

/** * Implements hook_node_presave(). */

function commerce_auction_node_presave($node) { $types = variable_get('commerce_auction_display_types', array()); if (in_array($node->type, $types) !== FALSE) { $product_reference = field_get_items('node', $node, 'field_product'); $product_reference = $product_reference[0]; $product = commerce_product_load($product_reference['product_id']); $price = field_get_items('commerce_product', $product, 'commerce_price'); $node->auction_starting_price[LANGUAGE_NONE][0]['amount'] = $price[0]['amount']; $node->auction_starting_price[LANGUAGE_NONE][0]['currency_code'] = $price[0]['currency_code']; } }
user1176783

How can I update file attachment and keep filename?

1 month 3 weeks ago

I understand changes of file attaching in D7, but problem is, if I delete and re-upload changed file, the deleted file is still on server and re-uploaded filename gets changed. If I understand correctly, removed file is deleted by cron, so there is a delay. Is it possible to get file deleted in real time, to avoid renaming of uploaded one?

Eric

Calculate config entity dependencies

1 month 3 weeks ago

I am the maintainer of the Authorization project. It provides a config entity type, the authorization profile. The profile requires two plugin types: provider and consumer. Other modules supply the provider and consumer.

I want to set the authorization profile dependencies to the modules providing the plugins.

Yaml:

dependencies: module: - authorization_drupal_roles - ldap_authorization

Php:

$config_factory = \Drupal::service('config.factory'); $config = $config_factory->getEditable('authorization.authorization_profile.ldap_group_to_role'); $config->setDependencies([ 'module' => [ 'authorization_drupal_roles', 'ldap_authorization', ], ]); $config->save();

How do I know which module a plugin is from? Does this need to be added as a property in the plugin annotation?

How can I determine the provider plugin is from ldap_authorization, and the consumer plugin is from authorization_drupal_roles?

https://www.drupal.org/project/authorization

Binary Alchemist

Multipage Registration form, Confirmation Page Security Issues?

1 month 3 weeks ago

I have a multipage registration form working on a site, but the confirmation page is supposed to show some of the information (account name and other data) after the account has been submitted/created. I can treat this confirmation page as the last page of the multipage form, but I'm concerned that the user can then press the back button on the browser, the session data will still be there, and they can then re-submit the same data again.

Another approach would be to end the session and display the data on a redirect page, but I could not find how Drupal 7 would pass this form data to the redirect page. There would be too much data to put it in the URL.

Does anyone have a suggested Drupal 7 method to achieve a confirmation page showing session data, but not allow the user to press back on the browser and re-submit the form again?

Jon Paul Vivere

how to exclude PHPUnit based functional tests from runnning?

1 month 3 weeks ago

I am trying to run only unit test for my custom module.

./vendor/bin/phpunit -c ./web/core ./web/modules/custom/testing_example --testsuite=unit .
But I keep getting the following error:

There were 2 errors: 1) Drupal\Tests\testing_example\Kernel\ExampleFixtureManagementTest::testNodeCreation Exception: There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh. See https://www.drupal.org/node/2116263#skipped-tests for more information.

I only want to run PhpUnit tests and not functional/browser tests.

awm

Webform sending emails when submission is created and completed - duplicate emails

1 month 3 weeks ago

We have a webform set to email both a notification and a confirmation after a user submits. Under ADDITIONAL SETTTINGS, Send email, only "When submission is completed" is selected for both. Two (duplicate) emails go out for each notification and confirmation. In the logs it says the emails are sent after the submission is created and then again after the submission is completed.

My question is, what can I do to to reduce the emails down to one each for notification and confirmation? I am guessing I have the settings incorrect. Hope this makes sense.

Using Drupal 9 and Webform version 6.2.2 The form was created with the Contact Us template.

Thank you.

tcweb

How to display an overlay image in modal window (Colorbox) upon hover

1 month 3 weeks ago

I have a series of images set up to display in modal lightbox-type windows – specifically, using the Colorbox module.

  • The goal is for each image to be paired with a companion graphic overlay which is displayed upon hover over the Colorbox display.
  • Think of it as (1) the photo, and (2) the "circles and arrows" overlay (maybe .gif or .png with transparent whites).

Can anyone verify its feasibility and suggest a path to this result?

Charles

How to override registration form message

1 month 3 weeks ago

I should override registration form message "Registration successful. You are now logged in." with String Overrides module it does not work, because new text is long and every line with other style, it is in Drupal 7 I try to do it in template.php , but no my code is working. Can anyone help me?

Evi

Unable to process Batch actions as Administrator

1 month 3 weeks ago

I'm working with a brand new install of Drupal 10 and am having issues with the administrator account (both the default one created at startup and my own personal account) having 'Access Denied' errors when attempting to perform Batch operations. This is specifically linked to attempts to batch delete users at the moment, but I likely have other issues with Batch actions as these commands are not currently being processed.

What I've tried so far:

  1. Clearing the cache from the web side of the application.
  2. Rebuilding the node permissions on the web side of the application.
  3. Re-building the cache from drush on the server.
  4. Making sure the user accounts are in the administrator group using drush.
  5. Re-creating the node permissions using drush and eval().

The site logs contain only the following in the logged error message denying access to Batch:

Path: /batch?id=13&op=start. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: in Drupal\system\Controller\BatchController->batchPage() (line 55 of /srv/advita-marketing/web/core/modules/system/src/Controller/BatchController.php).

The Batch information is being correctly created in the database.

I'm not currently using any third-party modules that affect permissions. The install is 99% vanilla Drupal at the moment.

I've checked Permissions under the People page and permissions for Administrator to perform the actions I'm expecting it to are checked as being active permissions.

I also have ruled out .htaccess as being a cause of the error as I'm running the application on Nginx.

Any help here would be appreciated.

Joseph Quinn

How to create an Enquiry form with ability to submit a collection of enquiries

1 month 3 weeks ago

I am building a new site which has a large selection of different products/services on offer, the information for each is shown in it's own node.

If the user has interest in a number of these services then I would like to give them the ability to 'add' the item to their enquiry along with a message. When they have added all of the items they are interested in they can then submit the enquiry.

Overall, the process shares similarities with an e-commerce workflow

  1. View product
  2. Add product to enquiry form builder with comment (choose options and add to cart)
  3. Browse other products and repeat steps 1&2.
  4. Once happy, review enquiry (checkout)
  5. If all is ok, submit enquiry (process order)

Using Drupal 7, how would you suggest I tackle this?

I only compared the process to e-commerce as it helped me think things through, the site isn't actually going to be selling the products. Strictly a tool to submit a detailed enquiry.

leeboyce

How to use feeds tamper to set default value from importer node?

1 month 3 weeks ago

I've got a number of feeds that I want to be able to import regularly. I setup feeds and attached them to a content type, ex. "My Feeds" which imports into another content type, "Article".

I also need to make sure that when these feeds come in, that I can set the default values in the target node. The use case is that I will be importing from feeds in multiple languages and want them associated with an author so I have created a couple of new fields in my importer content type:

field_language field_author

I want to be able to set the language and author value for each feed when I create the importer and have those associated every time I update but its not clear if any of the existing plugins do this.

I've also started writing my own custom plugin to pull in these values from the parent importer but I can't figure out how to access or load the importer object through a feeds tamper plugin.

Any pointers or is there a better way to acccomplish this task?

schnippy

What's the coding standard for class constants?

1 month 3 weeks ago

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore character.

Object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores; instead, they opt for various forms of camel case.

Unfortunately, Object-oriented code doesn't mention class constants at all.

Which of the following is correct?

  • const FOO_CONSTANT_VALUE = 'bar';
  • const CONSTANT_VALUE = 'bar';
  • const constantValue = 'bar';
user7

CORS localhost ajax request

1 month 3 weeks ago

I have an HTML page (http://localhost:8888/test/test.html) in which I'm trying to pull data from a Drupal 7 website.

I'm using this AJAX code with HTML-Request. I have tried JSON and the website prevents me from pulling, even I have added the following code to pull the data.

<?php header('Access-Control-Allow-Origin: *'); ?>

This is the HTML page that requests AJAX from Drupal 7 website. Could you please check it for me?

<script src="http://code.jquery.com/jquery-latest.js"></script> <script> (function ($) { $(document).ready(function () { $.ajax({ // The link we are accessing. url: "http://horizon-websolutions.com", // The type of request. type: "get", // The type of data that is getting returned. dataType: "html", error: function () { alert("error"); // Load the content in to the page. $("#output").html("<p>Page Not Found!!</p>"); }, beforeSend: function () { alert("not yet"); }, complete: function () { alert("done"); }, success: function (strData) { alert("success"); // Load the content in to the page. $("#output").html(strData); } }); // Prevent default click. return(false); }); })(jQuery); </script> <div id="output"></div>

Please help me telling the website to accept my localhost request to pull data from the server. I have tested the same code on a pure PHP page and it is working fine.

Mohammad Moussa

How do you join a custom table to a node from a field with hook_views_data()

1 month 3 weeks ago

I have a custom table that contains (for simplicity) two fields:

  • id
  • client_id

On my node content type, I have an integer type field called: field_dashboard_id. All my nodes have the field_dashboard_id set to ids from the custom table. I have a content view that I would like to also display the client id from the custom table. (FYI I am able to create a view if I use Dashboard Entries instead of Content but I want to use Content and join to Dashboard Entries)

I tried the following code but when I try to add a relationship, I am not seeing my custom table in Views.

/** * Implements hook_views_data(). */ function mydashboard_views_data() { $data = []; $data['mydashboard_site']['table']['group'] = t('Dashboard'); $data['mydashboard_site']['table']['base'] = [ 'field' => 'id', 'title' => t('Dashboard entries'), 'help' => t('Contains a list of dashboard entries.'), ]; $data['mydashboard_site']['table']['join'] = array( 'node' => array( 'left_table' => 'node__field_dashboard_id', 'left_field' => 'entity_id', 'field' => 'id', ), ); $data['mydashboard_site']['id'] = [ 'title' => t('ID'), 'help' => t('Unique Site ID.'), 'field' => [ 'id' => 'numeric', ], 'filter' => [ 'id' => 'numeric', ], 'argument' => [ 'id' => 'numeric', ], 'sort' => [ 'id' => 'standard', ], 'relationship' => [ 'base' => 'node', // The name of the table to join with. 'base field' => 'field_dashboard_id', // The name of the field on the joined table. // 'field' => 'nid' -- see hook_views_data_alter(); not needed here. 'handler' => 'views_handler_relationship', 'label' => t('Default label for the relationship'), 'title' => t('Title shown when adding the relationship'), 'help' => t('More information on this relationship'), 'extra' => [ [ 'field' => 'field_dashboard_id', 'value' => 'value', 'operator' => '=', 'numeric' => true, ], ], ], ]; $data['mydashboard_site']['client_id'] = [ 'title' => t('Client ID'), 'help' => t('The client id'), 'field' => [ 'id' => 'standard', ], 'filter' => [ 'id' => 'string', ], 'argument' => [ 'id' => 'string', ], ]; return $data; }

Update

Also tried the following:

$data['mydashboard_site']['table']['join'] = [ 'node__field_dashboard_id' => [ 'left_field' => 'field_dashboard_id_value', 'field' => 'id', ], ]; 'relationship' => [ 'base' => 'node__field_dashboard_id', // The name of the table to join with. 'base field' => 'entity_id', // The name of the field on the joined table. // ID of relationship handler plugin to use. 'id' => 'standard', // Default label for relationship in the UI. 'label' => t('Example node'), ],
albertski

Getting values on twig node template

1 month 3 weeks ago

I have installed ECK module in my website. Using it I have created a "report eck" entity in which I have different bundles like section, notes, etc., each containing different fields. I have my content type "Report" in which I have referred "report eck" entity using entity reference field. Now, in my nice template, I need to get various values including the bundle type, in which I am facing lots of trouble. My bundle type is coming up as following when I am doing kint() on my reference field, but I am not able to get this bundle type and many other values, please guide.

Also, it seems to be a protected values, so I navigated to "Available Methods" tabs and found method 'getEntityKey()' which seems to be useful, but how can I use it in twig template??

Dev

How come my view block is not loading using ajax?

1 month 3 weeks ago

We have a view, myview, that has an exposed filter title (text input). The view has Exposed form in block:Yes and so we load it onto the page under admin/structure/block. The block has a machine name of exposedform_myview_title.

We want to remove it from display and only load the view block on click of an icon. How come my view block is not loading when using ajax?

View Setup:

  • view_name = 'myview`
  • when creating view, view page setting -> "create a page" was set to true
  • view machine name = mypage
  • view use ajax = Yes
  • view block (displayed using admin/structure/block) machine name exposedform_myview

Error message

https://somesite/path/views/ajax?view_name=myview&view_block_id=mypage 404 (not found)

myjs.js

This will load the view itself and not the exposedform_myview_title block. We want the exposedform_myview_title to be displayed.

(function($) { 'use strict'; Drupal.behaviors.iconClick = { attach: function(context, setting) { $('#someid', context).once().each(function () { $(this).on('click', function(clickEvent) { // Use Ajax to load form. $.ajax({ url: drupalSettings.path.baseUrl + 'views/ajax', type: 'GET', // type: 'POST' not succesfull dataType: 'json', data: 'view_name=myview&view_display_id=mypage', //not successfull --> data: 'view_name=myview&view_block_id=exposedform_myview', success: function(response) { var output = response[1].data; $('.some-element').html(output); }, error: function(data) { alert('error'); console.log(data); } }); }); }); } }; })(jQuery);

page.html.twig

... <div id="someid">my icon goes here</div> <div class="some-element"> view block exposed form should go here </div> ...

we also tried to use Drupal.ajax, but that did not load the View into the required <div class="some-element">

(function($) { 'use strict'; Drupal.behaviors.iconClick = { attach: function(context, setting) { $('#someid', context).once().each(function () { $(this).on('click', function(clickEvent) { // Use Ajax to load form. var ajaxPath = '/views/ajax'; var view_info = { view_name: 'myview', view_display_id: 'page' }; var ajax_settings = { submit: view_info, url: ajaxPath, event: 'click' }; Drupal.ajax(ajax_settings); }); }); } }; })(jQuery);
usernameabc

How to safely output user input HTML in a twig theme [duplicate]

1 month 3 weeks ago

Very basic question:

I have a twig template were I want to output the HTML content of a CkEditor managed field within a node.

<div class="wrap-user-html"> {{ node.field_myfield.0.value }} </div>

This does not work, as it prints the html code with html entities. I'm getting e. g.

<div class="wrap-user-html"> &lt;p&gt;foo&lt;/p&gt; </div>

I could use |raw and it would work, but I read this is unsafe. Also when using raw, text format filters from the ckeditor settings seem to not get applied.

How do I do this right?

c1u31355

Programmatically add a translation with proper content moderation state

1 month 3 weeks ago

I am trying to add a node translation programmatically when a node is created (using hook_ENTITY_TYPE_insert). My code works fine except that the translation doesn't really have a content moderation state. My code is the following.

function mymodule_add_translation($node) { // get the current language, and determine the translation language $lang = \Drupal::languageManager()->getCurrentLanguage()->getId(); $langcode = ($lang == 'en') ? 'fr' : $lang; $node->setRevisionTranslationAffected(FALSE); $node->addTranslation($langcode, ['title' => $node->getTitle()])->save(); }

This is what the content_moderation_state_field_revision table looks like for two nodes; the first one was manually translated and the second one was translated using the above code.

I am clearly doing something incorrect. Any suggestion would be really appreciated.

JoelB
Checked
9 hours 45 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed