Drupal StackExchange

Uploaded file not shown in custom content type / Image not attached to content type

2 days ago

In Drupal 7, I am trying to upload an image that belongs to a custom type.

I click the Browse button, choose the file and upload. Until there, all seems to work well.

However, when I click next, instead of the add alt, title and text, I get only a screen that says Destination *, and with a Previous and Next buttons, as shown below. The save button is never displayed, and the image is not shown.

However, the image is there if I check the files through the admin, moreover, all goes well If I add the image through the file/add, it is just in the custom type that I get the error.

I am logged in as an administrator and I have all the permissions checked in Media and File Entity

My files folder permissions are 755, and the javascript console shows: 'Attr.nodeValue' is deprecated. Please use 'value' instead. in jquery.js

Resource interpreted as Script but transferred with MIME type text/html: "about:blank" in browser?render=media-popup&types[]=image&activePlugins=&enabledPlugins=&schemes[]=public&schemes[]=…:92 (anonymous function)

Thanks in advance for your help.

Update, this doesn't work with Image widget nor Media Browser widget. Same site works in PROD, I suppose it is something with the file system settings?

elneto

True/False exposed Views checkbox for Computed Field

2 days 1 hour ago

Imagine a user has ten fields of type "List(text)" which each have for their widget "Check boxes/radio buttons". Each one is displayed to the user as a single value checkbox which asks the user to state whether they agree with something or not.

A distinct Computed Field of data type TinyInt uses custom PHP to examine the values of these List(text) fields checkboxes. If all are checked the Computed Field is set to have the value of 1. If any or all are unchecked the Computed Field is set to have the value of 0.

(Ideally I would like the Computed Field to be of Boolean type - so simple TRUE/FALSE - but this does not seem possible out of the box. Anyway, the real question is the following.)

In a View with exposed fields, how can you use the Computed Field as an exposed field that offers the user a single checkbox: "Find all users where the Computed Field value is 1: [•]".

If this isn't directly possible, I'm happy to have a workaround that involves creating a distinct (hidden) field in the user profile and then uses this for the Views exposed filter search. But I can't think of a way to do this right now... Thanks.

penname

Are hooks cached?

2 days 3 hours ago

I am trying to alter a views result after it's executed, and before it's rendered. I was originally using hook_views_pre_render(viewExecutable $view), but that wasn't updating any of the view results for one reason or another, so I switched over to hook_views_post_execute(viewExecutable $view) which DOES update view results, however, both hooks only work immediately after a cache clear.

Is there a reason this was done? It seems pointless to have these hooks if they only fire based on cache clears or cache being updated.

I am using the hook to compare a field in a result row to an array, and if it doesn't match a value in the array, then it removes the views result so it doesn't show up in the view.

Like I said in the post, this works in the initial view visit immediately after a cache clear, but as soon as you refresh the page the view is no longer using the hook. I've disabled views caching in settings, but it still seems to be behaving this way.

I am also curious why my normal views display responds to the hooks, but my REST export display does not. Does it need different hooks?

The exact code I am using is below:

function tcrp_server_status_views_post_execute(\Drupal\views\ViewExecutable $view) { if ($view->id() == "server_list") { $steamid = \Drupal::request()->query->get('steamid'); if ($steamid == NULL || $steamid == '') { unset($view->result); } $u = \Drupal::entityQuery('user') ->condition('field_steam_id',$steamid); $result = $u->execute(); $user = \Drupal\user\Entity\user::load($result[1]); foreach ($view->result as $k => $v) { $display = false; foreach ($v->_entity->field_access_roles->referencedEntities() as $reference) { if (array_search($reference->id(),$user->getRoles())) { $display = true; } } if (!$display) { unset($view->result[$k]); } } } }
Ex0r

Get text_long field value with EntityMetadataWrapper

2 days 4 hours ago

I am trying to get data from a text_long type field using EntityMetadataWrapper, and from what I'm seeing on the interwebs, I should be using something like this:

$wrapper->{$field}->value();

or

$wrapper->{$field}->value->value();

However, if I use the first one, I get an array with format and value keys, but if I try the latter, I get an Call to a member function value() on null` error.

Do I have to use $wrapper->{$field}->value(); and manually get the value from the array? Or is there a more direct method? I've looked through the class, I don't see another method that gets the value data.

wonder95

Is it possible to disable taxonomy hierarchy?

2 days 4 hours ago

The site I am building uses fields (plus a custom module) to provide a richer set of relationships between taxonomy terms than the built-in hierarchy allows.

I want to remove/disable the built-in hierarchy. What I mean is that when a user is creating or editing a term, I do not want them to see the "Relations" section, and when they are viewing a list of terms in a taxonomy, I want the drag-and-drop functionality to only work for ordering, not indenting.

I know I can do this with another module using hook_form_alter() or the like, but is there an easier and quicker way to "turn off" this functionality in Drupal 8? I have a vague memory of (maybe in an earlier Drupal, or somewhere else) being able to specify, when you create a taxonomy, if you want it to be hierarchical or not, but I cannot find such a thing here.

naomi

How to save datetime field value in config?

2 days 5 hours ago

I have a custom module (mymodule) with a settings form. This form contains a datetime field (mydate) which I want to save in my modules config.

When I try to save this form I get an exception:

Drupal\Core\Config\UnsupportedDataTypeConfigException: Invalid data type for config element mymodule.settings:mydate in Drupal\Core\Config\StorableConfigBase->validateValue() (line 160 of core/lib/Drupal/Core/Config/StorableConfigBase.php)

The form field:

$form['mydate'] = array( '#type' => 'datetime', '#title' => t('My date'), '#default_value' => $config->get('mydate') )

The form submission handler where the error occures:

$config->set('mydate', $form_state->getValue('mydate));

I guess I have to set up my config schema to set up the "right type". Currently I have this one but it does not solve my issue:

mymodule.settings: type: config_object label: 'fancy module settings' mapping: mydate: type: datetime label: 'My date'

Any idea what I'm doing wrong or what is missing?

PS: using Drupal 8.2

Philipp Michael

#states and #ajax are not working on pop up

2 days 5 hours ago

I need to get form only with HTML. To do this, I've used delivery callback in hook_menu(). This is my sample code:

function test_menu() { $items['htmlform'] = array( 'access callback' => TRUE, 'page callback' => 'test_htmlform' 'delivery callback' => 'delivery_text_plain', 'type' => MENU_CALLBACK, ); return $items; }

In this form, I've used #states and #ajax.

I've another form which is in the normal callback. I need to show htmlform into this Drupal form. So I've written a ajax callback to 'htmlform', get html, paste it into the drupal form & show this in pop up.

This is my ajax callback:

$.ajax({ url: '/htmlform', success: function(data) { $('#formpopup').empty(); $('#formpopup').html(data); $("#form_demo_pup").modal({backdrop: 'static',keyboard: false}); Drupal.attachBehaviors($('#form_demo_pup')); } });

Now the drupal form page have all the CSS and JavaScript but the pop up (htmlform) have only the HTML.

On this pop-up, #states and #ajax are not working since it has no Drupal form JavaScript.

How do I fix this? Even I tried "Drupal.attachBehaviors" in my custom ajax.

Guru

Bibcite references from migration shows HTML tags in abstracts and notes, how to strip them?

2 days 5 hours ago

After a migration using the bibcite_migrate module, I retrieved my 2700+ references from a D7 site and the Bibliography module.

Unfortunately, HTML tags are visible on all abstracts and notes and they are not formatted.

I tried to manage the default display and table mode but I can only choose "Default" or "Trimmed" and the html tags are still visible.

When trying to display my references with Views, it's the same thing, I can't choose a text format that will decode the HTML tags (even with rewrite results and strip HTML tags options).

In the bibcite_reference table, all values contain HTML tags. I have tried to add "basic_html" for one reference (column bibcite_abst_e__format) but I see no changes.

How can I decode these HTML tags to cleanly display my abstracts and reference notes?

Thanks for any tip here.

Toki

Drupal Planet