Drupal StackExchange

Form submit POST renders page before submit handler is called

1 month 3 weeks ago

I have a search form in the header that is simply adding a search term to the current URL. If you are on example.com/list-page and submit a search, it just sends you to example.com/list-page?search=my-term-here.

When I submit the form, I've noticed that the full page has to be rendered before the form's submit handler is called. Since the search modifies the current list page's results, it seems redundant when submitting a search for "my-term-here" on example.com/list-page to have to render example.com/list-page again before the submit handler is called and then render the version I actually want: example.com/list-page?search=my-term-here.

I've hacked around this by doing this in my form:

// Set to the current path so we can redirect back there after submit. $form['submission_path'] = array( '#type' => 'hidden', '#default_value' => current_path(), '#weight' => -100, ); $form['#action'] = url('search-callback');

The search-callback does nothing:

function mymodule_search_callback() { return ''; }

The submit handler then does a redirect like this to get back to example.com/list-page?search=my-term-here.

// Redirect back to the page that submitted the search. $form_state['redirect'] = array( $form_state['values']['submission_path'], array( 'query' => array( 'search' => urlencode($search-term), ), ), );

Is there a better way to handle this? Can the form's submit handler be called before rendering the page the form is posting to?

bendiy

Login page when using a Zen's sub theme

1 month 3 weeks ago

I've created a website based on a Drupal 7 Zen subtheme and now I would like to create a login page for the administrator. When I navigate to http://mysite.com/?q=user, I return to the main page as specified in the page.tpl.php file. I would like to have a manual login page, so I tried following the following tutorial: https://drupal.org/node/350634. My template.php looks like this:

function camuse_theme() { $items = array(); $items['user_login'] = array( 'render element' => 'form', 'path' => drupal_get_path('theme', 'camuse') . '/templates', 'template' => 'user-login', 'preprocess functions' => array( 'camuse_preprocess_user_login' ), ); return $items; } function camuse_preprocess_user_login(&$vars) { $vars['intro_text'] = t('This is my awesome login form'); }

And my user-login.tpl.php file like this:

<p><?php print render($intro_text); ?></p> <div class="camuse-user-login-form-wrapper"> <?php print drupal_render_children($form) ?> </div>

However, when I navigate to http://mywebsite.com/?q=user, I still go to the home page. I don't know what I'm doing wrong here, I've checked the names and everything seems fine. Could anyone help me with this?

Devos50

Use token from parent entity

1 month 3 weeks ago

In a drupal 10 site I have a content type called article with an entity reference field on it called "Related nodes". Those related nodes are of type page. On the page content type there is a wysiwy field with tokens formatting enabled.

How can I access tokens of the parent entity of type article within the wysiwyg field on node of type page that is referenced in the "Related nodes" field?

devunder

LIKE operator to load taxonomy term

1 month 3 weeks ago

I want to retrieve a taxonomy term using this line:

$term = $this->entityTypeManager->getStorage('taxonomy_term') ->loadByProperties(['myfield' => 'mytext']);

How can I rather use the 'LIKE' operator we have in SQL, so that in case the 'myfield' contains a text and not a string in the database, it still works? Thanks for your help

el sparrow

View field with JavaScript code in it

1 month 3 weeks ago

I have content type which has text field. Each node has its own javascript code which is set in to the text field. Text field is PHP Code format.

When I add this field to Views block site load ONLY the javascript in that text field. Whole other drupal content is not loaded. When I remove this field from views then site works normally.

This script works on full node but not in the Views. What can cause this? What ways to fix it?

Script is from Tradedoubler (third party advert) :

<script type="text/javascript"> var uri = 'http://url.com' + new String (Math.random()).substring (2, 11); document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset=""></sc'+'ript>'); </script>
hene

Include Full Taxonomy Term inside a Content Type?

1 month 3 weeks ago

I'm working on a project where we want to pull in the title, description, and an image from selected taxonomy terms and include them in content of a predetermined content type. The content type is already displaying the Term with a link, but I want to display the description and an image along with it.

While I am sure this is possible, I'm not sure what the best method would be to accomplish this. I'd rather not hard-code it into a content-type template.

Topplestack

how to automatically create other entities when creating an entity

1 month 3 weeks ago

I have 4 entity types. All types have a relation to each other. For now let's call them A, B, C and D. How can I allow a user (let's say userA) to create an entity of type A so that entities for B, C and D are also created at the same moment. UserA has the permission to create A entity types and is not the author of the automatically created entities of type B, C and D. Is there a way to automatically create these related entities?

BassPlaya

Drupal Planet

Drupal Association blog: Skills Upgrade: Drupal 7 to Drupal 10 - a community story

1 month 3 weeks ago

The Drupal Association has published this guest blog on behalf of author John Picozzi, in collaboration with Chat Hester, Stephen Cross, Nic Laflin, Mike Anello, and AmyJune Hineline.

“Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it's the only thing that ever has.”  - Margaret Mead

In my mind, the above quote distills the Drupal Community down to one sentence and perfectly describes its mission. Many in the community also use “Come for the code, stay for the community” to highlight that Drupal is more than just open-source software; it’s a community of committed citizens focused on helping each other, growing skills, and developing world-changing open-source software. As many are aware, Drupal 7 will reach end-of-life (EOL) at the end of this year. Many are working to move their sites to Drupal 10, while others are looking to “Level Up” their skills to work with the latest and greatest Drupal version. This story highlights the journey of one developer and how we as a community came together to help him (and hopefully many others) achieve Drupal 10 readiness. 

Our story starts with Drupal Slack and the following message from Chad Hester (chadhester). 

“Hey, I have an idea that I wanted to run by you… Since I'm looking for more contracting work, getting back in to Drupal development is on my radar. I haven't done development work since Drupal 7, though. I'm out of practice since ~2015. There are lots of people who learn Drupal for the first time, but I wonder if anyone has documented their experience re-learning Drupal. Perhaps that's something that could be good as a Talking Drupal mini-series. What do you think?”

I thought it was an interesting idea and told Chad I would take it back to the team at Talking Drupal to discuss. The Talking Drupal team, Stephen Cross (stephencross), John Picozzi (johnpicozzi) & Nic Laflin (nicxvan), discussed and loved the idea. Working with Chad, they refined the show format and structure to something like a scrum meeting, where each week they reviewed what was done, what challenges were faced, and what tasks should be completed in the week to come. While brainstorming about the mini-series format they also thought of community members who could be involved. 

At Talking Drupal, we strive to provide the Drupal community a platform for learning and awareness. We also include the community in creating that content as much as possible. To that end, we identified Mike Anello (ultimike) of DrupalEasy as a great choice for a mentor and AmyJune Hineline (volkswagenchick) of the Linux Foundation as a host for the series. After identifying all the folks we planned to include, Stephen started outreach, and quickly, everyone was onboard. Within three weeks of the above Slack message, we started recording our first episode. From that point, we started recording weekly and planned eight episodes. 

Everyone contributed to the goals of this mini-series and added their perspective. We wanted to ensure the series would help the community move from Drupal 7 development to Drupal 10 development. However, we also wanted to go above and beyond with real open-source contributions. Mike provided that via a capstone goal of having Chad contribute an automated test to a real-life contrib project. This goal was a perfect outcome and would not only empower Chad to contribute but could empower anyone who watched the series. Overall, we have set out to bring in community members to build content for others. Allowing community members to push/pull others forward in their skill set. 

Today, we are happy to share the first episodes of the Talking Drupal Mini Series: Skills Upgrade. A developer's journey from Drupal 7 to Drupal 10. Through this effort the community has come together to support its members to grow and learn. The power of the Drupal Community isn’t in the software we develop, it's in the people we empower. Those people are empowered to learn, grow, and use amazing open-source software. Indeed, I believe this group of thoughtful, committed citizens have done their little bit to change the world. 

Episodes will be released over the next few weeks. Thank you, and Enjoy!

Nonprofit Drupal posts: March Drupal for Nonprofits Chat: NTC Wrap-Up and DrupalCon Planning

1 month 3 weeks ago

Join us THURSDAY, March 21 at 1pm ET / 10am PT, for our regularly scheduled call to chat about all things Drupal and nonprofits. (Convert to your local time zone.)

This month we'll be giving a recap of last week's NTC, and an update on our plans for DrupalCon Portland, including the Nonprofit Summit and the recently announced discount for nonprofit attendees!

And we'll of course also have time to discuss anything else that's on our minds at the intersection of Drupal and nonprofits.  Got something specific you want to talk about? Feel free to share ahead of time in our collaborative Google doc: https://nten.org/drupal/notes!

All nonprofit Drupal devs and users, regardless of experience level, are always welcome on this call.

This free call is sponsored by NTEN.org and open to everyone. 

  • Join the call: https://us02web.zoom.us/j/81817469653

    • Meeting ID: 818 1746 9653
      Passcode: 551681

    • One tap mobile:
      +16699006833,,81817469653# US (San Jose)
      +13462487799,,81817469653# US (Houston)

    • Dial by your location:
      +1 669 900 6833 US (San Jose)
      +1 346 248 7799 US (Houston)
      +1 253 215 8782 US (Tacoma)
      +1 929 205 6099 US (New York)
      +1 301 715 8592 US (Washington DC)
      +1 312 626 6799 US (Chicago)

    • Find your local number: https://us02web.zoom.us/u/kpV1o65N

  • Follow along on Google Docs: https://nten.org/drupal/notes

View notes of previous months' calls.

The Drop Times: The Drupal Project Update: Highlights from DrupalSouth Sydney 2024

1 month 3 weeks ago
Join us as we dive into the heart of DrupalSouth Sydney 2024, held at the iconic Sydney Masonic Centre. Discover the insights from Dries Buytaert's keynote on 'The Drupal Project Update,' the push for innovation and contributions, and the unifying power of the Drupal communities from Australia and New Zealand. Stay tuned for exclusive updates and takeaways.