Drupal StackExchange

Base path and user picture uploading

1 month 3 weeks ago

So I recently migrated my site between servers. I think this is causing some issue with the base path of Drupal, which in turn affects the image upload path when a user tries to upload an image to his/her profile.

So, before migrating, some data was already uploaded to some of the users and their images and paths work just fine. The path is as follows for example:

www.example.com/sites/default/files/styles/thumbnail/public/pictures/picture-125-1377507580.jpg

But now, when I'm trying to add new users and when I upload new pictures, the image doesn't get uploaded and the path to the image is as follows:

www.example.com/new/?q=sites/default/files/styles/thumbnail/public/pictures/picture-125-1377507580.jpg

Why is this happening? How do I change the Drupal base path? Thanks

KaushikTD

Define a resource of Service module, But 'access callback' cannot work

1 month 3 weeks ago

This following is my resource:

For clearly read, I delete some line.

/** * Implementation of hook_services_resources(). */ function baidu_push_services_services_resources() { $resources = array(); $resources['message']['actions']['send'] = [ 'file' => array( 'type' => 'inc', 'module' => 'baidu_push_services', 'name' => 'baidu_push_services', ), 'access callback' => '_message_access', 'callback' => 'baidu_push_services_send', 'args' => array( array( 'name' => 'uid', 'type' => 'string', 'source' => 'data', 'optional' => FALSE, ), ]; return $resources; }

In order to test my 'access callback' function will be invoked, I always return FALSE in my 'access callback' function:

function _message_access($op = 'view', $args = array()) { return FALSE; }

But when I try to use curl command line to test with no SESSION and no Token, but It work!(return the right result to me), Did that mean 'access callback' not be invoked?

So I try to use drush cc all to clear cache, But still above problem.

Moon soon

Is it possible to show views exposed filters in the facet current search block?

1 month 3 weeks ago

I have a facet search with Facet API, Search API, and a Solr backend with the Search API Views integration. I am using the Current Search block (part of the Facet API module) to display the currently selected facet options.

However, I am also using Views, and I have two exposed filters with the autosubmit button on the page. The problem is that users can select one of the views exposed filters and it will not appear in the Current Search block, so it is not obvious to the user that the results are being further filtered.

I am also using Facet API Pretty Paths, so I have a path that looks like this:

myexample.com/s/n/1/b/2&items_per_page=8&jp=1&d=-

n/1 and b/2 are facets, &items_per_page=8 is the views pager, and &jp=1 and &d=- are the views exposed filters.

My goal is to somehow make it clear to the user that Views exposed filters are affecting the results. If it's possible to modify the Current Search block, I would like to do that, but if not, creating a separate block/ctools content type to notify the user that the exposed filters are applied would also be acceptable.

I'm not aware of any modules that show the applied exposed filters, so I'm thinking about writing code to check the query string for jp and d and then printing messages based on the results. If there is an easier approach, I would be glad to hear it.

Patrick Kenny

Is it possible to change the form submit handler from within a validate handler (need to redirect to another form depending on values entered)

1 month 3 weeks ago

I have an initial webform (based on 3.x of webform module/Drupal 7) that needs to redirect to a second form if yes is specified in a yes/no choice. Otherwise if No, the first form should submit normally (with a webform result).

Also, if yes is entered on the first form, on submitting the form, the webform result is not to be stored for this form, but the webform result will be stored on the second webform. Values entered in the first form are carried through to the second, to autofill, I use the PHP _SESSION variable to do this.

I'm having difficulty getting this to work completely. It always seems that I can get one part of the above working, but not the other. I'm using the standard approach of hook_form_alter and within this trying various combinations of setting the validate array and submit array and the form redirect property to do the redirect from the first and second form.

My approach now is to have a validate handler function to change the submit handler if the yes is chosen (for proceeding to the second form). Submitted values on the first form are available to the validate handler. The submit handler can do the redirect to the 2nd form.

But when I change the submit handler from within the validate handler, I see that this change gets overwritten by Drupal itself and I don't know why.

I have also found that the submit handler - which I use to set the form redirect, for the 'yes' choice - will not work if other submit handlers are present in the submit handler array. I have to empty the array and have only my function in it.

I had wanted to deal with the yes/no choicepoint at this stage in my own submit handler, but if I had to 'throw away' the other submit handlers, then the 'No' path won't work - the webform result won't get submitted.

Another approach I tried, to counteract my deleting of the other existing default submit handlers, was to programmatically submit a form for the the first form for the 'No' path so that it would get saved. However doing this I got an error about the number of submissions possible, even though it was set to unlimited (-1) in the config. From that I concluded that it was due to that I had already started the first form as a visitor and somehow the webform system 'notes' that, so programmatically submitted form would exceed that supposed maximum.

Note: I can't upgrade to webform 4.x as there are other forms on the site which may be impacted unexpectedly.

therobyouknow

Menu Block won't display when a page has a view block

1 month 3 weeks ago

I have the Menu Block module installed to provide some contextual menus for certain areas of a site. These generally work great. But I have a few pages where I'm adding a Views generated block to the bottom of the page, and on these pages the menu block seems to ignore the fact that these pages exist in the menu system and will not show anything.

If you have experienced this before and have a solution that's fantastic. Otherwise I'm hoping for some pointers as to where to look around for potential issues.

It seems to be related to the block using the row style instead of the fields style. If I change it to fields, the Menu Block module works as expected.

Chris Budy

Why is an entity reference view field only showing one view result?

1 month 3 weeks ago

I have a form field on a node create form that is an entity reference, referencing a view that displays all of the appropriate results. The view displays users with a relationship to a content field on the user, so the fields returned are all content. There is also an argument that takes the logged-in user ID. On the node create form, the field in question, when set to show unlimited results, only shows the last result from the view. I feel like I've gone over any technical reason this could happen, now I'm wondering if this is a bug with user views, or elsewhere. I haven't found anyone reporting this yet in my searches, so I thought I'd post it here.

Steve

How can I import staged configuration?

1 month 3 weeks ago

I'm trying to import configuration with drush cim. I'm getting

Rename operation for simple configuration. Existing configuration system.site and staged configuration domain.config.xxx.system.site.

I looked at config/sync and there are a bunch of domain.config.xxx.system.site files. I looked at settings.php and there's no mention of the domain keyword. I was referred https://drupal.stackexchange.com/questions/150481/how-can-i-import-the-configuration-on-a-different-site but that's a different issue. Search engines don't have information on this specific issue. How can I import these?

Kartagis

How to change values views exposed filter based upon view results?

1 month 3 weeks ago

I have a view which, in addition to showing event nodes, also shows "fake" event nodes. The "fake" event nodes are inserted in hook_views_pre_render().

The view also has an exposed filter to filter out content tagged with a certain term ID on the event_type field. The exposed filter list has gotten too large so now it would make sense to only show the terms in the list that can filter out the view results (including the "fake" events).

Now I tried this with hook_form_alter(), but the problem is that the "fake" event nodes aren't available by using views_get_view_result() and I'm not sure what other function could be used to do that here.

I tried using dpm($view); in hook_views_pre_render(), hook_views_pre_build(), and hook_views_pre_view(), but I could not find how to change values in the exposed filter in any of those.

Where can I see the values of the view result at the same time as the value options in the exposed filter?

CR47

Set select list option value

1 month 3 weeks ago

I'm trying to set value of select list programmatically with hook form alter

I have select list with options:

$options = array(125 => 'USA');

and setting value like this

$form['field_news_rubrique']['und']['#options'] = $options

But this don't work.

if i change options like this

$options = array(0 => 'USA');

it's working

if i have multiple value in options like this :

$options = array(124=> 'EN', 125 => 'USA');

it's working too

stomerfull

How to render a paragraph field in Twig in correct language?

1 month 3 weeks ago

I've got nodes with hero images. The hero images are a paragraph field with unlimited cardinality, each with an image and a translatable text. For design reasons I need to print the hero images in page.html.twig (using Twig Tweak for simplicity)

{{ drupal_field('field_banner_slide', 'node', node.id) }}

The hero slider has some options like timer, size,... which are other fields on the same host node, and pulled in during preprocess

function MYTHEME_base_preprocess_field(array &$variables, $hook) { $parentEntity = $element['#object']; if ($parentEntity && $variables['field_name'] == 'field_banner_slide') { // attach JS library // add HTML data attributes on this field based on other field values of same host node // ...and so on... } }

All worked fine until my site went to the translator. My slider always returned the default lang. Next I tried setting the language in page.html.twig

{{ drupal_field('field_banner_slide', 'node', node.id, 'default', language.getId()) }}

This works for every other field - except Paragraphs. I've also tried the alternative

{{ node.field_banner_slide|view('default', language.getId()) }}

but still the same language problem.

I've already checked the source code from Twig Tweak, it seems to correctly set the language

public function drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL, $check_access = TRUE) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $id ? \Drupal::entityTypeManager()->getStorage($entity_type)->load($id) : \Drupal::routeMatch()->getParameter($entity_type); if ($entity && (!$check_access || $entity->access('view'))) { $entity = \Drupal::service('entity.repository') ->getTranslationFromContext($entity, $langcode); if (isset($entity->{$field_name})) { return $entity->{$field_name}->view($view_mode); } } }

I've been really digging here, but I can't find any single error. How do I get my correctly translated paragraphs?

PS: I don't want to use {{ drupal_entity('paragraph', my_field_banner_slide_target_ids, 'default', my_langcode) }}, because I also need the preprocessing from the host field.

Hudri