Drupal StackExchange

List field: translated values are not translated

1 day 22 hours ago

In my Drupal 8 project I have some list fields. For example maybe a field "project type" with the following key|values, coming from the original language German:

1 -> öffentliches Projekt 2 -> privates Projekt

Which I translated in the field's settings:

1 -> public project 2 -> private project

The field is NOT set to be translatable because the value should not be changed in a translation: the project type is in all languages the same! But now when I go to the node edit page, when I view the node or when I add this field as exposed filter to views I always see the German values of the field no matter what is set as the current language of the page. When I change the field to be translatable the value of the list field can be changed in English translation -> so it can come that a project is "public" in German and "private" in English what is not the desired result.

How do I get the translated values of a list field to be used in form element and node view when the list field itself should not be translatable?

Tobias Krause

How to add custom sort order to a taxonomy field list?

1 day 23 hours ago

I am trying to sort the list of content according to the weight order given to taxonomy term.

Terminology used:

content type : contact-person-details

taxonomy : company vocabulary which has list of company names like company A, company B, ...

session company : every user has a company which is stored in session, users have similar company names too.

how it works now: Imagine I am from "company A" stored in my session. Based on my company, content in a view is getting shown (company A is the taxonomy term used for filtering). Views are used to filter the content type contact-person-details. Varies from company to company which was tagged to content, based on user session company.

What I am trying to achieve? Image below helps in understanding the visual concept. Imagine list (Test one, Test sort, ...) shown are the company vocabulary lists, just like (company A, company B, ...) I want an additional field or textbox just to the side of each term showing to add weight. This weight should be available in the view so that I'm able to making sorting based on the weight allocated for each content.

I would like to know is there a existing possibility to weight the taxonomy list in field.

If it is still complex to understand I will try to edit my explanation.

Arun

Trigger redirect after Webform Remote Post Handler posted successfully

2 days ago

I've made a webform with a handler. This handler does a Remote Post towards an API. This API is actually a custom module within the Drupal install which (after some logic) passes all of the preprocessed data towards another API. When that is passed successfully I get a redirect URL back from them, but whatever I use (TrustedRedirectResponse or just normal RedirectResponse) it won't redirect. It just reloads the form.

How to solve this?

Jessica IX

Automatically trigger Acquia pipelines job when Drupal content is updated

2 days 1 hour ago

My team is fetching a large portion of our site's content at build time by using the i18n Gatsby plugin and downloading content from Drupal. The content we are fetching at build time rarely needs to be changed, but when it does, we now have to manually run an Acquia pipelines job and deploy the new artifact in order to display the updated content. This is inconvenient and time-consuming, especially since the content authors making these changes are typically not folks who have access to run a pipelines job or deploy a build.

Is there a straightforward way to automatically trigger a pipelines job when content is updated/added/deleted in Drupal? So far, the only solution my teammates and I have been able to think of is to use the Drupal Webhooks module to trigger a GitHub workflow, which would then do something like create a GitHub tag, which we could then configure to trigger a pipelines job. (We currently have our repo set up to start a pipelines job whenever a PR is opened in GitHub.)

Can we do this in a less roundabout way, for instance by using the Drupal Webhooks module to directly start a pipelines job in Acquia? From what we could tell, there isn't a way to do this, but it would be nice to avoid having to go through so many steps to set it up.

Also, is there a way to automatically deploy artifacts to a given environment? (I don't think we would want to do this in production, because it seems kind of risky, but might be nice to have it set up this way for one of our lower environments.)

Thank you in advance!

Amy

Paypal express checkout doesn't add taxes

2 days 1 hour ago

I am creating a site where they only want to use paypal express checkout (using drupal 7 /Ubercart 3.1). The problem is that it doesn't display the taxes when processing the order. I know it doesn't have the address info when it goes to the express checkout but when it comes back, it adds the shipping price but no taxes. Is there a way to add the taxes in?

I have been through all the options and don't see anything related to this.

I have also tried modifying inside the paypal module itself:

In the function uc_paypal_ec_review_form_submit I see that they add the shipping info if it is not there but when I try to add taxes the same way, the tax functions don't work.

I do see the line "subtotal excluding taxes" which I believe is being generated by the taxes module but no tax is actually applied.

If I use the paypal standard checkout, the tax is applied once the address info is filled in.

Any help would be appreciated.

ghazuria

comment form custom validation

2 days 2 hours ago

I am using a custom validation in my Drupal 7 comment form.
I want to match the comment_body against a word "example" so if someone just type "example"in the comment body then it will show a error message that only the word "example" is not allowed. After reading drupal api documentation i codded like this:

function mango_form_comment_node_news_form_alter(&$form, &$form_state, $form_id){ $form['comment_body']['#prefix'] = '<div class="sm">Post your comment now!</div>'; $form['actions']['submit']['#value'] = 'Post Your Comment'; $form['#validate'][] = 'banana'; } function banana($form, &$form_state) { if ($form_state['comment_body'] == "example") { form_set_error('comment_body', 'Your comment can not contain example!'); } }

Do not working :'( what i'm missing? Thanks

rakibtg

How do I get <drupal-media> to appear?

2 days 2 hours ago

I am trying to use the Drupal Media insert button in the CKEditor5 module. (Important - the existing images were included using CKEditor4 and are inline images, not using Drupal Media.)

I upload the image I want to the Media Library and then select it in CKEditor5.

You can see that the image appears in the dialog box. But when I save nothing appears on the actual page.

The HTML, where the image should appear, looks like this:

<tr> <td> <drupal-media data-entity-type="media" data-entity-uuid="5acaee67-a8fe-4265-81d2-82099838073b" data-align="center">&nbsp;</drupal-media> </td> </tr>

How do I get it to show? I've read everything I can find but no joy.

Adaddinsane

How to disable caching of _custom_access callback

2 days 2 hours ago

My module has several pages which use a custom access callback. The conditions for access may change from call to call so this needs to be checked every time. When I am logged in, the access callback seems to be accessed every time as expected, but when testing as an anonymous user, the access callback only executes once and then it seems the result is saved until the next time I manually clear caches.

I turned off caching on the route, but the _custom_access callback never is called for subsequent visits to the page unless I clear caches.

How can I make the access callback result not be cached? Is that changed in routing.yml or in the access callback itself?

mtsxc.routing.yml

mtsxc.basic_search: path: '/test/search' defaults: _title: 'test Basic Search' _form: '\Drupal\mtsxc\Form\BasicSearchForm' requirements: _custom_access: '\Drupal\mtsxc\securityCheck::access' option: no_cache: 'TRUE'

src/securityCheck.php

<?php use Drupal\Core\Access\AccessResult; final class securityCheck{ public function access(AccountInterface $account, Request $request){ //some computations if($allowed){ return AccessResult::allowed(); } elseif(!$authenticated){ return AccessResult::forbidden('NeedLogin'); } elseif(!$agreed){ return AccessResult::forbidden('NeedAgreement'); } }

src/EventSubscriber/mtsxcExceptionSubscriber.php

<?php declare(strict_types = 1); namespace Drupal\mtsxc\EventSubscriber; use Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * @todo Add description for this subscriber. */ final class mtsxcExceptionSubscriber extends HttpExceptionSubscriberBase { protected function getHandledFormats() { return ['html']; } public function on403(ExceptionEvent $event) { $exception = $event->getThrowable(); if ($exception instanceof AccessDeniedHttpException) { switch($exception->getMessage()){ case 'NeedLogin': { $response = new RedirectResponse('/test/login'); $event->setResponse($response); break; } case 'NeedAgreement': { $response = new RedirectResponse('/test/agreement'); $event->setResponse($response); break; } } } } }

mtsxc.services.yml

services: mtsxc.event_subscriber: class: Drupal\mtsxc\EventSubscriber\mtsxcExceptionSubscriber tags: - { name: event_subscriber }
Kevin Finkenbinder

Image Files Uploaded via REST got Temporary status - Cannot be refereced by Media Image

2 days 3 hours ago

Drupal 8.9.11

Image File Uploaded via REST gets "status - Temporary" while setting explicitly "status" case to True server error 403 (code in python)

"status": [ { "value": True } ],

The sever returns code 403, an exception:

Status: 403, Message: {"message":"Access denied on creating field \u0027status\u0027."}

The error on the server: $ vendor/bin/drush watchdog-show

access denied Warning Path: /themag_dp8/entity/file?_format=hal_json. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: Access denied on creating field 'status'. in Drupal\rest\Plugin\rest\resou

If I'll not specify "status = true" The next REST call to Create Media fails to reference it due to its temporary status.

payload = { "name": { "value": name }, "field_image": [ { "target_id": file_id } ], "field_description": [ { "value": description }, ], "bundle": [ { "target_id": "image" } ], "_links": { "type": { "href": oauth.base_url + REST_TYPE_MEDIA_IMAGE }, oauth.base_url + "/rest/relation/media/image/thumbnail": [ { "href": oauth.base_url + "/file/%d" % file_id + FORMAT_HAL_JSON } ], oauth.base_url + "/rest/relation/media/image/field_image": [ { "href": oauth.base_url + "/file/%d" % file_id + FORMAT_HAL_JSON } ] } } Status: 422, Message: {"message":"Unprocessable Entity: validation failed.\nfield_image.0.target_id: This entity (file: 119) cannot be referenced.\n"}

Server error: $ vendor/bin/drush watchdog-show

access denied Warning Path: /themag_dp8/entity/paragraph?_format=hal_json. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 120 of php Error Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException: Unprocessable Entity: validation failed. field_image.0.target_id: This entity (file: 119) cannot be referenced. in

When I manually, via web site admin (https://drupal8.site/admin/content/files), change the file status to "Permanent", this Create Media REST call succeeds to create a new media/image entity.

Seems the Rest user missing some security allowances, but which one? Did anybody succeed to create a node consisting of the teaser image, paragraph video and so?

Sure I'm not the first who attack this issue, where the relevant documentation, working code examples?

Vladimir P.

Drupal Planet