Drupal StackExchange

User can't access own private files via Views

3 days 6 hours ago

I've set up a private directory sites/default/files/private and use it for a file field.

As an admin, everything works as expected when uploading and viewing a private file.

As a user who uploads a private file, I can only download own private files with the Views formatter Download link (example.com/file/585/download?token=TcBjzT2I), but not view them via Generic file (example.com/system/files/private/mypic.jpg) or other formatters. When using the latter, I get

"Access Denied You are not authorized to access this page."

Permission "View own private files" for role enabled. Even enabling "View private files" has no effect.

What am I missing?

xinxin

Render parent paragraph depending on dynamic data from child paragraph (e.g. db query)

3 days 7 hours ago

Here's my problem (D8):

There's a content type concert. In a paragraph type concerts_list a list of upcoming concerts (concert nodes) is displayed. This concerts_list paragraph is referenced in field_right_column of another paragraph of type 2_columns.

What I want to do is: Hide the right column if there are no upcoming concerts in the concerts paragraph.

My issue is that the outer (parent) paragraph is rendered and preprocessed before the child paragraph and the resulting render array only includes #theme, #paragraph and #cache but not the actual render array used to render the paragraph.

How can I access a child paragraph's render array from the parent? I don't want/need to access the child paragraph's fields since the concerts are no field because the data is simply added to the build array in hook_entity_type view.

When rendering the 2_columns paragraph I need to know whether or not there are any upcoming concerts and if not I'd like to hide the right column.

Is there a better approach to achieving a similar result?

I'd appreciate any hints/tips/...!

Here's the relevant code:

function MODULE_paragraph_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { $bundle = $entity->bundle(); if ($bundle === 'concerts_list') { // Get the max number of concerts we want to display. $max_concerts = (int)$entity->get('field_count')->value; $build['concerts'] = MODULE_get_upcoming_concersts($max_concerts, 'teaser'); } elseif ($bundle === '2_columns') { // Determine whether to show one or 2 columns depending on the number of // upcoming concerts in 'concerts_list'. // It would also be ok to do that in twig but I'd need to get the data // somewhere. } } function MODULE_get_upcoming_concerts($limit = 0, $view_mode = 'default') { $entity_type_manager = \Drupal::entityTypeManager(); $query = $entity_type_manager ->getStorage('node') ->getQuery() ->condition('type', 'concert') ->condition('field_date', strtotime('midnight'), '>') ->sort('field_date', 'ASC'); if ($limit) { $query->range(0, $limit); } $nids = $query->execute(); if (count($nids) < 1) { return []; } $nodes = $entity_type_manager->getStorage('node')->loadMultiple($nids); return $entity_type_manager->getViewBuilder('node')->viewMultiple($nodes, $view_mode); }
witti

Cannot configure the site as SAML SP with simplesamlphp_auth

3 days 8 hours ago

I have a functioning SAML IdP, implemented with LemonLDAP::NG. I know it functions because it works with Nextcloud as an SP. I've also successfully configured a DokuWiki SP in the past.

The IdP, the Nextcloud SP and the Drupal 8 SP are all behind an Nginx reverse proxy. All of them are directly reachable from my IP, but I have restricted access from other IPs.

I have been trying on and off for a year to make SAML login work with Drupal 8, using simplesamlphp_auth, but without success. I have lost count of how many articles I have read on the net, which all suggest that configuring SAML is trivial. Sadly, not for me.

Currently, when I select the Drupal 8 SP under 'Test authentication sources' in the 'Authentication' tab, I get the following error:

Too many redirects occurred trying to open “https://www.xxxx.tld/simplesaml/module.php/core/authenticate.php?as=wmh-www-sp&%5CSimpleSAML%5CAuth%5CState.exceptionId=_568428306a7ad7ad7bf8f8f47a94940de364239c67%3Ahttps%3A%2F%2Fwww.xxx.tld%2Fsimplesaml%2Fmodule.php%2Fcore%2Fas_login.php%3FAuthId%3Dwmh-www-sp%26ReturnTo%3Dhttps%253A%252F%252Fwww.xxx.tld%252Fsimplesaml%252Fmodule.php%252Fcore%252Fauthenticate.php%253Fas%253Dwmh-www-sp”. This might occur if you open a page that is redirected to open another page, which then is redirected to open the original page.

The log file contains repeated occurrences of the following error messages:

2019/04/03 22:31:48 [error] 21251#21251: *982 FastCGI sent in stderr: "PHP message: simplesamlphp DEBUG [e54b9408f4] Session: 'wmh-www-sp' not valid because we are not authenticated.

PHP message: simplesamlphp DEBUG [e54b9408f4] getIdpMetadata: METADATANOTFOUND('%' => '\'https://cloud.xxx.tld/saml/metadata\'')

PHP message: simplesamlphp DEBUG [e54b9408f4] getIdpMetadata: METADATANOTFOUND('%' => '\'https://cloud.xxx.tld/saml/metadata\'')

PHP message: simplesamlphp DEBUG [e54b9408f4] Saved state: '_f37c552249cf34b640de1dac7ad22b1481c763fc0f:https://www.xxx.tld/simplesaml/module.php/core/as_login.php?AuthId=wmh-www-sp&ReturnTo=https.xxx.tld.php.php-www-sp'

PHP message: simplesamlphp DEBUG [e54b9408f4] saving key SimpleSAMLphp.session.161a8f86a89cf6e93f36117cc21a26af to memcache" while reading response header from upstream, client: NN.NNN.NNN.NNN, server: www.xxx.tld, request: "GET /simplesaml/module.php/core/authenticate.php?as=wmh-www-sp HTTP/2.0", upstream: "fastcgi://unix:/var/run/php-fpm-www.sock:", host: "www.xxx.tld", referrer: "https://www.xxx.tld/simplesaml/module.php/core/authenticate.php"

2019/04/03 22:31:48 [error] 21251#21251: *982 FastCGI sent in stderr: "PHP message: simplesamlphp DEBUG [e54b9408f4] loading key SimpleSAMLphp.session.161a8f86a89cf6e93f36117cc21a26af from memcache" while reading upstream, client: NN.NNN.NNN.NNN, server: www.xxx.tld, request: "GET /simplesaml/module.php/core/authenticate.php?as=wmh-www-sp HTTP/2.0", upstream: "fastcgi://unix:/var/run/php-fpm-www.sock:", host: "www.xxx.tld", referrer: "https://www.xxx.tld/simplesaml/module.php/core/authenticate.php"

(www.xxx.tld is the SP, cloud.xxx.tldis the IdP, wmh-www-sp is the entityID of the SP.)

Specific things I do not understand:

  • we are not authenticated - I have logged into the simplesamlphp_auth interface
  • METADATANOTFOUND('%' => '\'https://cloud.xxx.tld/saml/metadata\'') - this is the address of the IdP's metadata and is correct as such

I created file metadata/saml20-idp-remote.php from the IdP's metadata URL, https://cloud.xxx.tld/saml/metadata using simplesamlphp_auth's metadata converter under the "Federation" tab.

Can anyone help me to make sense of all the above?

Steve

Stephen Winnall

emailing users in user reference field with rules

3 days 10 hours ago

I am working on a site for an academic conference. Right now, we have two content types (1) proposal and (2) peer review. In the proposal content type, an author can add multiple presenters to a user reference field. When the node is saved, I have a rule that loops through the user reference field and sends an email notification to all the presenters that the proposal has been submitted. Works great!

Now the question. I want to send an email to that same group of users when someone else posts a peer review. I have figured out how to notify the "author" of the proposal but I want to notify all the users listed in the node reference field.

Right now my rule is set up as follows: Event: after saving new content Conditions: content is of type > peer review Actions: Fetch entity by property: -Value: node -Value: node reference -Data selector: node Variable label: Fetched proposal Variable name: fetched_proposal

Then I have a loop: Data selector: fetched-proposal Current list item Variable label: Current proposal item Variable name: proposal_list_item

Then I have an action to send the mail. Since I've looped over the proposal connected to the peer review, I have available a token for the presenter field which contains the node reference. I've used that token in the "To" value field.

I think this should work but I don't get emails when testing.

When I check my log messages I see this error: The loop Loop () fails the integrity check and cannot be executed. Error: Data selector fetched-proposal: for parameter list is invalid.

Can anyone help me figure this out?

knowledges33ker

Custom migration source plugin not enabled in source site error

3 days 11 hours ago

I'm trying to write a custom source plugin for a d7-d8 migration. I want to extend the Drupal\node\Plugin\migrate\source\d7 Node.php plugin.

I'm getting the following error when I try to run the migration from the UI:

Migration my_node_page did not meet the requirements. The module my_xtra is not enabled in the source site. source_module: my_xtra.

When I run drush ms I get a different error

No database connection configured for source plugin variable

The database connection key is specified in the group yml and works for other migrations which don't use the custom source plugin.

Here's my yml file

id: my_node_page label: Node Basic Page audit: true migration_tags: - Drupal 7 - Content migration_group: my_group source: plugin: my_xtra_node node_type: 'page' process:

Here's my custom plugin.

<?php namespace Drupal\my_extra\Plugin\migrate\source; use Drupal\node\Plugin\migrate\source\d7\Node; /** * Drupal 7 node source from database. * * @MigrateSource( * id = "my_xtra_node", * source_provider = "node", * source_module = "my_xtra", * * ) */ class NodeXtra extends Node { /** * {@inheritdoc} */ public function query() { // Select node in its last revision. $query = $this->select('node_revision', 'nr') ->fields('n', [ 'nid', 'type', 'language', 'status', 'created', 'changed', 'comment', 'promote', 'sticky', 'tnid', 'translate', ]) ->fields('nr', [ 'vid', 'title', 'log', 'timestamp', ]); $query->addField('n', 'uid', 'node_uid'); $query->addField('nr', 'uid', 'revision_uid'); $query->innerJoin('node', 'n', static::JOIN); // If the content_translation module is enabled, get the source langcode // to fill the content_translation_source field. if ($this->moduleHandler->moduleExists('content_translation')) { $query->leftJoin('node', 'nt', 'n.tnid = nt.nid'); $query->addField('nt', 'language', 'source_langcode'); } $this->handleTranslations($query); if (isset($this->configuration['node_type'])) { $query->condition('n.type', $this->configuration['node_type']); } return $query; } }

Thanks!

Peter

Show tax from shipping?

3 days 12 hours ago

I'm building on Commerce Kickstart 2. The problem is that for shipping it displays only flat price, there is no tax amount calculated seperately.

Is it possible to shipping like:

Express shipping subtotal 10€
Shipping tax 23% 1,23€
Total: 11,23€

Or show shipping as line item so that shipping tax is calculated to product taxes amount?

Tuomas Leppänen

"Unrecognized response content type" in Acquia Migration Accelerate

3 days 12 hours ago

I am trying to run the Acquia Migrate Accelerate tool on a production D7 database. I've got as far as migrating Public Files and each time it stops after about 2000 out of 7000 entries. I also get the same message when trying other migrations e.g. Webform submissions, again it fails part way through.

There are HTTP errors in the console log:

http://hse.local/acquia-migrate-accelerate/api/migration/process/27 GET 500

The website encountered an unexpected error. Please try again later. LogicException: There is no active operation. in Drupal\acquia_migrate\Batch\MigrationBatchManager->isMigrationBatchOngoing() (line 654 of modules/contrib/acquia_migrate/src/Batch/MigrationBatchManager.php). Drupal\acquia_migrate\Controller\HttpApi->migrationProcess() call_user_func_array() (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58) Drupal\Core\StackMiddleware\Session->handle() (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23) Stack\StackedHttpKernel->handle() (Line: 718) Drupal\Core\DrupalKernel->handle() (Line: 19)

I've successfully run this process on a UAT site with has the same structure but much less data (5000 items to migrate rather than 70000), so I'm wondering if it's struggling with the volume of data

Does anyone have any experience of this particular error, or of how well AMA performs with larger migrations in general?

Hadden Uff

Drupal Planet

The Drop Times: Embracing Technology with Drupal

3 days 7 hours ago

In 2024, technology has reached new heights, impacting our lives like never before. With AI becoming more common and exciting updates on the horizon, technology is shaping our world significantly.

Technology continues to redefine the way we live, work, and connect. New features, updates, and innovations emerge daily, shaping our world remarkably. At the heart of this transformation lies Drupal, the dynamic content management system that empowers individuals and businesses to navigate the digital realm easily and confidently. Drupal opens limitless possibilities in website development, offering a platform where creativity knows no bounds.

Drupal streamlines the process of creating and managing websites, putting the power of customization and control at our fingertips. With its intuitive interface and robust features, Drupal allows users to craft online experiences that are not just functional but truly exceptional.

Technology is advancing rapidly, and Drupal is here to make it accessible and beneficial for everyone. With its user-friendly features and adaptability, Drupal simplifies website creation and opens doors to endless possibilities.

Let's review the latest news covered by The Drop Times (TDT) last week.

In an Interview with Alka Elizabeth, sub-editor, TDT, Irina Zaks, Co-Founder and CTO at Fibonacci Web Studio, discusses her transition from a background in physics to web development, emphasizing the importance of clear, simple solutions in complex projects. She highlights the Fibonacci sequence's role in her design philosophy, advocating for harmony and simplicity in web development. Zaks also reflects on the unique challenges of academic websites and her efforts to promote open-source software within academia, particularly through her work at the Stanford Open Source Lab. The interview is a precursor to Stanford Web Camp. 

Head to the concluding part of our series, "Drupal Page Builders—Part 4: Distributions," crafted by André Angelantoni, Senior Drupal Architect, HeroDevs. The article discusses the practicalities and considerations of using Drupal distributions for page building. It emphasizes that while distributions can simplify the setup process, especially for non-technical users, they often involve complex maintenance and may slow down upgrades due to dependency on the distribution maintainers. The piece advises conducting a proof-of-concept for the most complex page layouts to ensure the chosen solution can handle the requirements, highlighting that many teams opt for minimal module use to maintain flexibility and control.

Explore the articles curated by Kazima Abbas regarding the featured speakers who presented their sessions at EvolveDrupal Atlanta. The first part features Michael Herchel, Mary Blabaum, Allison Vorthmann, Andy Waldrop, and Jesse Dyck.  Topics range from an Inclusive Design Approach to Drupal 7's End of Life on website security and from leveraging Drupal for scalable software products to insights on migrating to Drupal 10. The second part shifts to topics including The Fourth Decade of Website Deployments, the Crossroads of Website Evolution, and the updates from WCAG 2.1 to 2.2. John Cloys, Penny Kronz, and Steve Persch are featured in this segment. 

The upcoming Drupal Developer Days in Burgas, Bulgaria, from June 26-28, 2024, at Burgas Free University, has announced Suzanne Dergacheva and Frederik W. as keynote speakers. DrupalCamp Iberia 2024 has officially announced its schedule for the upcoming gathering on May 10 and 11 at PACT in Évora, marking a significant event in the Drupal community's annual calendar. The Network of European Drupal Associations (NEDA) has scheduled a meeting on April 24, 2024, led by Esmeralda Tijhoff. This meeting aims to foster connections among Drupal Associations globally, sharing experiences and discussing support strategies.

DrupalCon Portland 2024 extends a special offer to students, recent graduates, and individuals with Drupal Training Certification obtained since 2022, providing an opportunity to purchase tickets for the event at a discounted rate of $50. The DropTimes has been announced as the official media partner for The LagoonCon Portland 2024. DrupalSouth has made their talks from DrupalSouth 2024 accessible online via their YouTube channel! Now, you can catch up on all the insightful discussions and presentations from the comfort of your home. A particularly engaging story narrated at the event is the talk by Dallas Ramsden, a story of human resilience. The Eclipse Foundation has initiated a collaborative effort to establish common cybersecurity standards in response to the upcoming European Union's Cyber Resilience Act. This initiative involves multiple open-source organizations and aims to harmonize secure software development practices across the industry, addressing both regulatory requirements and the broader challenge of securing open-source software. The Greek Drupal Community celebrated a resurgence with the Greece Spring Sprint 2024, where experienced developers across Athens, Thessaloniki, and Patras collaborated to address numerous issues. We have received pictures via Georgios Andreadis of the event, take a look here.

Jesus Manuel Olivas, Co-Founder and CEO at Octahedroid, announced the initial release of two significant Drupal modules—Visual Editor and Decoupled Preview Iframe. A recent update from Drupal.org saw Gábor Hojtsy outlining the forthcoming release plans for Drupal 11, noting significant dependency updates and two potential release windows later this year. Obviously, this has created discussions in the community. Paul Johnson, a long-time participant and photographer at Drupal events, has announced an initiative by the Promote Drupal team to create the first official Promote Drupal Image Library. The team calls for submissions from photographers within the Drupal community who are willing to contribute their work under a Creative Commons license. 

While there are undoubtedly more stories to share, our current constraints may necessitate a temporary pause in our coverage.

To get timely updates, follow us on LinkedIn, Twitter and Facebook. Also, join us on Drupal Slack at #thedroptimes.

Thank you,
Sincerely
Kazima Abbas
Sub-editor, The Drop Times

Talking Drupal: Talking Drupal #446 - Test Driven Development

3 days 10 hours ago

Today we are talking about Test Driven Development, Why it’s important, and How it improves development with guest Alexey Korepov. We’ll also cover Test Helpers as our module of the week.

For show notes visit: www.talkingDrupal.com/446

Topics
  • What does the term Test Driven Development (TDD) mean
  • Does Drupal make use of TDD
  • What makes TDD different from other methods of Development
  • Do you have to change your way of thinking
  • What are some good resources to learn TDD
  • Do you have any pointers for teams looking to get started
  • Are certain kinds of projects better suited to TDD
  • How have dev teams adapted to TDD
  • Any advice on environment setup
  • Any special tools
Resources Guests

Alexey Korepov - korepov.pro Murz

Hosts

Nic Laflin - nLighteneddevelopment.com nicxvan Martin Anderson-Clutz - mandclu Matt Glaman - mglaman.dev mglaman

MOTW Correspondent

Martin Anderson-Clutz - mandclu

  • Brief description:
    • Have you ever wanted an API that could dramatically simplify the process of writing Drupal unit tests? There’s a module for that.
  • Module name/project name:
  • Brief history
    • How old: created in Sep 2022 by today’s guest, Alexey Korepov
    • Versions available: 1.3.0 compatible with versions of Drupal 9.4 or newer, right up to Drupal 11
  • Maintainership
    • Actively maintained, latest release less than 3 months ago
    • Security coverage
    • Test coverage, would be ironic if it didn’t
    • API Documentation is available, linked from the project page
    • Number of open issues: 2 open issues, which are actually feature requests
  • Usage stats:
    • 5 sites officially, but modules or sites can leverage Test Helpers without enabling it, and this usage is recommended, so the number is actually higher
  • Module features and usage
    • Provides a new container that automated tests can leverage to perform common tasks with much less code.
    • For example, you can create a user or a node with a single line of code
    • You can also mock more complex operations like an entityQuery or loadMultiple call, again with a single line of code
    • Traditionally, writing unit tests is more complicated because by design they run without fully bootstrapping Drupal
    • That means that your test needs to mock functions or services in the code you’re testing which can result in units tests being much longer than the code they’re testing
    • Test Helpers also allows your tests to leverage existing mocks and stubs for popular services
    • The project page also links to the recording and slides for a talk Alexey gave about Test Helpers at DrupalCon Pittsburgh last year, if you want to do a deeper dive

The Drop Times: Customer Benefits from Pantheon—Lytics Partnership Explained

3 days 10 hours ago
Pantheon and Lytics have teamed up to redefine the landscape of website personalization, introducing a solution announced at the Google Cloud Next ‘24 conference. This collaboration offers a transformative approach by leveraging generative AI to provide sophisticated personalization tools, which were previously complex and expensive but are now streamlined and accessible.

By integrating Lytics' Personalization Engine, companies can deploy tailored digital content strategies within 30 days—significantly faster than the traditional months-long process. This partnership simplifies the personalization process and emphasizes using first-party data, aligning with privacy standards, and moving away from reliance on third-party cookies. Embrace this new digital marketing era with Pantheon and Lytics, where advanced technology meets user-centric privacy.