Drupal StackExchange

How do I display an image using the Dynamic Background module?

1 month 3 weeks ago

I have been struggling to get the Dynamic Background module working for users' profiles. The profiles are displayed in a panel.

I enabled the Panel and User sub-module and after hours of trial and error I found a CSS combination that seems to work: #page #main-wrapper.

So the image displays as a background. But if I go to /user/[uid]/backgrounds to enable a background image for that user, it works but the image displays for ALL users, even when the other users have not enabled a background image.

I am at a loss because I thought that everything after user/[uid] only affected that user.

Any idea what I am doing wrong?

user14666

Composer installing Tripal module only above v4 and if continuing with v4, getting error with Chado module

1 month 3 weeks ago

As part of college course work, I am required to make a genomic database with a local website with basic features. I have installed Drupal 10.2.3 with PostgreSQL 14.11 and PHP 8.3.4.

My primary question is, should I continue with Tripal version 4 even though it is still in development? If no, how do I downgrade to stable v3.10 when facing this error?

When trying to install (or downgrade to) Tripal v3.10 using

sudo -u www-data composer require 'drupal/tripal:^3.10'

I am getting following error

Problem 1 - Root composer.json requires drupal/tripal ^3.10, found drupal/tripal[dev-4.x, 4.0.0-alpha1, 4.0.0-alpha2, 4.x-dev (alias of dev-4.x)] but it does not match the constraint. Installation failed, reverting ./composer.json and ./composer.lock to their original content.

My composer.json only contains the below

{ "require": { "drush/drush": "^12.4", "drupal/core": "^10.2" } }

I am new to Drupal as well as website development in general, and figured I would face less issues with v3 than v4 (which is still in development).

As a side note, I tried continuing with drupal/tripal:4.0.0-alpha2, and was able to proceed until I got error in Chado installation via Home > Administration > Tripal > Data Storage > Chado > Install Chado. From my limited understanding, it has something to do with missing "drupal_chado_installations" table but it seems to exist when I give command

SELECT * FROM information_schema.tables WHERE table_name = 'drupal_chado_installations'

I am also adding the Chado installation error if someone feels it is better to continue with Tripal v4 @ http://localhost/admin/tripal/storage/chado/install

The website encountered an unexpected error. Try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "drupal_chado_installations" does not exist LINE 3: "drupal_chado_installations" "i" ^: SELECT "i"."install_id" AS "install_id", "i"."schema_name" AS "schema_name", "i"."version" AS "version", "i"."created" AS "created", "i"."updated" AS "updated" FROM "drupal_chado_installations" "i"; Array ( ) in Drupal\tripal_chado\Database\ChadoConnection->getAvailableInstances() (line 279 of modules/contrib/tripal/tripal_chado/src/Database/ChadoConnection.php).

Drupal\Core\Database\StatementWrapperIterator->execute() (Line: 851) Drupal\Core\Database\Connection->query() (Line: 239) Drupal\pgsql\Driver\Database\pgsql\Connection->query() (Line: 525) Drupal\Core\Database\Query\Select->execute() (Line: 155) Drupal\pgsql\Driver\Database\pgsql\Select->execute() (Line: 279) Drupal\tripal_chado\Database\ChadoConnection->getAvailableInstances() (Line: 47) Drupal\tripal_chado\Form\ChadoInstallForm->buildForm() call_user_func_array() (Line: 536) Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283) Drupal\Core\Form\FormBuilder->buildForm() (Line: 73) Drupal\Core\Controller\FormController->getContentResult() call_user_func_array() (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 627) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 181) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58) Drupal\Core\StackMiddleware\Session->handle() (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28) Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32) Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50) Drupal\ban\BanMiddleware->handle() (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36) Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51) Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704) Drupal\Core\DrupalKernel->handle() (Line: 19)

My settings.php file already contains the database connection detail so many solutions mentioning that are not working

$databases['default']['default'] = array ( 'database' => 'teak_wood_genes_db', 'username' => 'postgres_molecular', 'password' => '**********', 'prefix' => 'drupal_', 'host' => 'localhost', 'port' => '5432', 'driver' => 'pgsql', 'namespace' => 'Drupal\\pgsql\\Driver\\Database\\pgsql', 'autoload' => 'core/modules/pgsql/src/Driver/Database/pgsql/', );
s-135

How to eliminate direct access to files in private directory?

1 month 3 weeks ago

I have set up my Drupal 7 site for private files in a directory above root (../private). I also set my filefield on my node type to upload the image files to that private directory.

I have two user roles: man and woman. Both user roles can create nodes of a certain type, containing that image file field. Men can never see another man's photo; same thing for women. Men can always see a woman's photo; same thing for women.

Here are my current results:

When a man visits a woman's node, he can view the photo within the node content: http://example.com/members/76/gallery/public/photo-123

When that man views the page source and copies the image URL, he can view that image directly in his browser: http://example.com/system/files/styles/apply_simplecrop/private/pictures/1/Public/filename.jpg?itok=ABC123&sc=abcdefghijklmnop

If that man shares that direct link with another man, that other man can view that picture as well. If he shares the direct link with a woman or a non-logged-in user they are served an Access Denied message and cannot view that picture.

If a man tries to access that image URL without the "itok=" text in the link, he receives an Access Denied message.

My desired result in all of those examples above is to display an Access Denied message.

The ../private directory has an htaccess file containing Deny from all.

Am I missing a step? What can I do to securely deny direct access to those files in the way that I described above?

Thanks!

hockey2112

How to add custom option value to select field in Webform and have them save with the submission?

1 month 3 weeks ago

I have a Drupal 7 webform when I need to dynamically populate a select field's options. I'm currently using hook_form_alter() and setting the values on the like so:

<?php $form['submitted']['left']['select_field_name']['#options'] = $new_options; </php>

This works for displaying the new options on the webform creation but the values are not saved with the form.

I know there is a hook_webform_select_options_info() hook to create predefined options but it does not take any parameters so I have no way to pass a value from the webform to tell it how to dynamically create the options.

Is there any way to create a dynamic select option list and have it save the values that were not in the original Webform select values list?

quantumized

Group node from OG membership doesn't work

1 month 3 weeks ago

I want to create some views to display Group information on Group content pages. E.g. Display contact info from the group in a block/pane in the sidebar.

I did this before, by using the default OG Content view and add the relations.

  1. I add the relationship OG membership: Group Node from OG membership, and sets its relation to (OG membership from node)
  2. Set the contextual filter to provide a default value (Current OG group from context) and keep relation set to the default OG membership from Node.
  3. Add fields and set their relation to Group node from OG Membership.

This isn't working though, it gives no results when viewing on Groupcontent-pages. It gives only results when viewing the Grouppage itself. I do not know why this is not working the way it should. As I recall I never had this problem before.

I used Organic Groups 7.x-2.7 with Panopoly 7.x-1.30. I have this on 2 separate installs (one on Acquia site, and one in my VM). The VM has only Panopoly and OG (and dependencys) installed as extra so it's almost vanilla.

I have enabled OG Context of course.

How can I solve this? Without these views it's a pain for the user to see in which groupcontext they are browsing.

EDIT: I installed a vanilla drupal (Not Panopoly). Installed OG + dependencys. Then I created an empty view and added the following: 1. Relationship: OG membership: OG membership from Node group (required) 2. Contextual: (OG membership from node group) OG membership: Og membership ID and Current OG group from context

This works! However, this doesn't work in Panopoly... Is this the new way to work with OG and Groupinfo on groupcontent pages?

The SQL-querys views does are exactly the same. Though on Panopoly there are no results. On Vanilla Drupal there is. How can I debug this?

Marcel

How to set a field value from parent template in Twig?

1 month 3 weeks ago

I have node--article--teaser.html.twig which calls image-formatter.html.twig to printout the field_image. Everything works fine except that I don't want the field_image itself to be a linked. i.e image-formatter.html.twig should not find a url to only print an img tag.

I have tried the following in node--article--teaser.html.twig:

{#{ content }#} {% set content.field_image[0]['#url'] = null %}{% endset %} {{ content.field_image }} {{ label }}

The second line causing the following error:

Twig_Error_Syntax: Unexpected token "punctuation" of value "." ("end of statement block" expected) in "themes/saidbakr/templates/node--article--teaser.html.twig" at line 78. in Twig_TokenStream->expect() (line 87 of vendor\twig\twig\lib\Twig\TokenStream.php).

While {{ content.field_image[0]['#url'] }} prints the url without any problems!

The image-formatter.html.twig code is as the following:

{% if url %} <a href="{{ url }}">{{ image }}</a> {% else %} {{ image }} {% endif %}

There is no any suggestion from twig debug about any alternative template for image-formatter.html.twig

Also using Theme Hook image_formatter as saidbakr_preprocess_image_formatter will not be an option because it is not possible to know the view context, i.e teaser or full, or content types to restrict this interaction for articles type. I think that the most simple way is from Twig, but how?!

SaidbakR

How to programatically change file user owner

1 month 3 weeks ago

I'm using the Services module. I can upload files through web services, but the problem is that all the created files have the same owner, the user account used for the web services. I would like to change this user, but I don't know how to do it.

I have been looking for the functions defined in the file.inc file, but I haven't found a function to change this. How could I change the file's owner?

briast

hook_editor_js_settings_alter()

1 month 3 weeks ago

I am using hook_editor_js_settings_alter() to disallow HTML tags in Ckeditor. It is only working in node edit form, and Ckeditor is in edit mode. Wen I preview the published page it allows the tags in my disallow custom hook.

The following code was a test to disallow <h1> tags with the class name myHeader2. If I change the class name to myheader, it work in edit mode and published mode. Is the class name the problem?

use Drupal\Core\Form\FormStateInterface; use Drupal\editor\Entity\Editor; function mymodule_editor_js_settings_alter(array &$settings) { foreach ($settings['editor']['formats'] as $name => $value) { $settings['editor']['formats']['rich_text']['editorSettings']['disallowedContent'] = 'h1(myHeader2)'; } }
paul cappucci

Add print button in the "Review order" page

1 month 3 weeks ago

I want to know, is there any way to add print button to "Review order" page.

by clicking this button, a pop up page is loaded with good style for print mode and user can print the cart items , taxes and all information in Review order page.

Please guide me.

Mehrdad201

SearchApiQuery - possible to remove a filter?

1 month 3 weeks ago

The query parameter that is passed to search_api_query_alter has SearchApiQueryFilter member. It contains a protected array of filter elements. I can add to this by calling the createFilter() and filter() methods, but it does not appear that there is a way to remove a filter through the API. Can this be done?

cdonner