Manage Display Field Label not changing: inline does not work

2 days 12 hours ago

I have the same problem as question 212176 and discovered it has to do with CSS. I have 2 (local) sites both with module ds enabled. I configured in both a field where I want the label and the value in one line: inline

With the classy-theme, this works fine. With the IceMagic theme it does not.

I have "inspect element"-screenshots of both. As there is no float:left with IceMagic, I believe this is the reason the label stays above.

Where and how to fix this?

sigridt

Implementing custom entity forms

2 days 13 hours ago

In Making use of the admin UI, Step 3 - Implement the entity adding/editing form, it says that you need to implement "a" form with the ENTITY_TYPE_form() signature for add/edit/clone operations...

However the wiki page is not specific in regards to whether you should implement one or two forms. I explain - the example creates two "entities": a "regular" entity, and a "bundle" entity. The example then implements ENTITY_TYPE_form() for the "bundle" kind of entity ONLY.

In attempt two answer the question: "Should I implement one or two forms?" I looked at the source code of both the Model and the Profile2 modules. The source of my confusion is that the Profile2 module implements only one form - like in the example - for the "bundle" kind of entity. But on the other hand the Model module implements two forms: one for the "regular" entity, and another one for the "bundle" entity. Why? What's the correct use case? What's the difference between the two implementations? What additional ability does implementing the "regular" entity form give us, if any?

amateur barista

Alter the path of the more link from Views

2 days 14 hours ago

In Drupal 8 how do I alter the more link?

I need to give it a path which is based on a taxonomy id that is based on the current path (where the view is on) which has the taxonomy name in the path.

The current page also has a field which has this taxonomy name as a result. (but changes per page)

--

I'm trying to retrieve the taxonomy ID based on the taxonomy that is placed on the node and give the id to the more link

I am not sure if this is clear. But I have a views page with filters. And the taxonomies are the filters. Certain pages (theme pages) have their own taxonomy directed to it with a views block. The more link of that block links to the views page, I want the link to automatically check the filters of the taxonomy that is being used on these theme pages.

TheDom

node reference ordering

2 days 15 hours ago

I have a content type "Review" and there there is dropdown for brands, I want to order dropdown list by alphabetical order. is there any way to reordering drupal node reference dropdown?

Zia

Render entity reference field with link in node template

2 days 16 hours ago

I have a content type with an entity reference field to select a user. Now I would like to render this field in the node template so that the field links to the user profile. I set the format of the field to "Label" in Manage Display and clicked on the gear so the label is linked to the reference entity.

But because I am printing the field programmatically it doesn't seem to work.

Here's what I do in my node template:

$field_user = field_get_items('field_collection_item', $item, 'field_user'); $field_user_output = field_view_value('field_collection_item', $item, 'field_user', $field_user[0]); print render($field_user_output);

Does anyone know how to do this?

Smos

Checkboxes in a simple form are not displayed

2 days 17 hours ago

I have a simple form in a custom module that works well and is displaying my select as it should.

$form = \Drupal::formBuilder()->getForm('Drupal\efq\Form\FilterForm'); $form["container"] = array( 'categories' => array( '#title' => t('Select a Category'), '#type' => 'select', '#options' => array( 1 => t('Option 1'), 2 => t('Option 2'), 3 => t('Option 3'), ) ) );

I would like to change Select for Checkboxes. According to this, "Checkboxes" structure is the same as per "Select". But when I change '#type' => 'select' for '#type' => 'checkboxes' there are no checkboxes created and I got the 2 following warnings:

Notice: Undefined index: #title_display in Drupal\Core\Render\Element\Checkboxes::preRenderCompositeFormElement() (line 20 of core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php). Notice: Undefined index: #id in Drupal\Core\Render\Element\Checkboxes::preRenderCompositeFormElement() (line 30 of core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php).

Adding these in an array makes the notice messages disappear but the checkboxes are still not showing.

Any idea of what's going on ?

Sebish

How to create a parent content type which consists of other child content types?

2 days 18 hours ago

I want to create custom content type (parent) which consists of other custom content types (children). Is this feasible in Drupal 8? Or I should do it programmatically?

Example: I want to have custom content type called Task, and another custom content type called Subtask. When a user creates a task, the user has to complete some fields (id, name), and should then create some Subtasks which are children of this Task. For the subtask some fields are to be completed also. In the end, each task will have some data such as:

  • name = "task_one".
  • description = "this task should do ..".
  • subtasks = {"subtask_one","subtask_two"}.
Drupal new user

Where does redirect from default search to apachesolr_search occur?

2 days 20 hours ago

We're using the apachesolr_search module on our site. (This is a site I inherited fully coded, so there's tons going on that I'm not intimately familiar with yet.) We have a search block that has been customized (see this post for details; we did eventually get the radio buttons to display, although in a really dirty, non-drupal way.)

I'm trying to get the form values on submit. Forgetting for a moment the radio buttons, I can't even figure out a way to get the value of the search box. Obviously it's getting passed to the solr search, but when I look at the Net panel in Firebug, there are no POST requests, only GET. In my submit function (which does run), I've tried print_r('$_POST'), echo $form_state['values']['search_box'] (where search_box is the element name of the actual form element), tried looping through $form_state and printing all key/value pairs... nothing. Not a single one of these returns anything.

Obviously there's a redirect occurring somewhere that sends the value of the search_box to the solr search module to build the GET request, but I can't for the life of me figure out where it's happening. I think in order to see the values of the posted form, I'd need to intercept the values before the redirect - how do I do that?

EmmyS

Two-way Entity Reference?

2 days 21 hours ago

I'm building a site for a school, with several content types:

  • A Class holds the general info about a class: description, tuition, etc. One field in the Class type is an Entity Reference for an Instructor.
  • An Instructor is the teacher of a Class.

When adding a new Class, the user will add an Instructor using the Entity Reference field (as an "autocomplete" widget). However, I also want the list of Instructors to link to the Classes each one teaches. How do I do this without having to enter the data on both the Class page and the Instructors page?

Robert D.

Updated from Drupal 8.9.20 to 9.0.0, but can't run update.php due to errors

2 days 22 hours ago

Here's what I get when attempted to run update.php:

Requirements problem

Errors found

MISSING UPDATES FOR: SYSTEM The installed version of the System module is too old to update. Update to a version prior to 9.0.0 first (missing updates: system_post_update_layout_plugin_schema_change, system_post_update_entity_reference_autocomplete_match_limit).

MISSING UPDATES FOR: TAXONOMY The installed version of the Taxonomy module is too old to update. Update to a version prior to 9.0.0 first (missing updates: taxonomy_post_update_configure_status_field_widget).

MISSING UPDATES FOR: TEXT The installed version of the Text module is too old to update. Update to a version prior to 9.0.0 first (missing updates: text_post_update_add_required_summary_flag).

MISSING UPDATES FOR: VIEWS The installed version of the Views module is too old to update. Update to a version prior to 9.0.0 first (missing updates: views_post_update_limit_operator_defaults, views_post_update_remove_core_key).

Dan

Passing data to a field formatter via views with referenced fields?

2 days 22 hours ago

In creating a 'traffic light' field formatter, how to access views data stored in an entity 2 levels up?

The traffic light is 'green' if speed is 'good'. There is a radar entity which has the location and last reading (inherited structure). The radar might have more than one road associated with it.

The view queries roads. The display is content with a custom display type and layout manager. The 'traffic light formatter has access to the speed field as this is the field it is formatting. It has access to the radar entity passed to the field formatter. I can't see a way to access the road entity which has the speed limit field. The speed limit is required to work out whether the recorded speed is greater than the speed limit.

class RoadTrafficLightFormatter extends FormatterBase { public function viewElements(FieldItemListInterface $items, $langcode) { foreach ($items as $delta => $item) { $this->trafficLight($item->getEntity()); } } protected function trafficLight(NodeInterface $radar) { $minimumLevel = $radar->get('field_gauge'); // ? How to get the road that is referencing the traffic light to find the speed limit? } }

Two ways came to mind

  • views-pre-render event. Where to save the road nid?
  • views_field_formatter module allows you to define the view in the field formatter settings. Use this to load the view a second time?
Interlated

Using theme_preprocess_node i'm trying to add a class to all images on the page

2 days 23 hours ago

My code below is not working and i'm not sure why. I've tried a few variants. according to the KPR variables output, the image I'm trying to access is here.

$variables['field_about_image'][0]

i think the 0 signifies it is the first (and only in this case) image on the page w/ the machine field name 'field_about_image'. so i wrote my code as:

function myTheme_preprocess_node(&$variables){ if($variables['type']=='basic_page_with_pic') { echo '<script>alert("my func running")</script>'; //Verified it's working $variables['field_about_image'][0]['class'] = 'myclass; } }

i've also tried this, just to get a class attribute added

$variables['field_about_image'][0][] = 'class';

also the title attribute comes up as empty. so just as an execrcise i tried this.

$variables['field_about_image'][0]['title'] = 'some title;

any help on how to do this would be greatly appreciated!

TopTomato

How To Upload Image From Media Library Programmatically?

3 days ago

I enabled latest version of media module to upload images in wysiwyg. It is working fine. There is no problem. I want to upload images programmatically from media library.
Below is my code.

function test_form_upload_form_alter(&$form, $form_state) { $form['settings']['apply_now_image'] = array( '#type' => 'media', '#title' => 'Image for apply now', ); $form['#submit'][] = 'test_upload_form_submit'; } function test_upload_form_submit(&$form, $form_state) { global $user; if (!empty($form_state['values']['apply_now_image'])) { $file = file_load($form_state['values']['apply_now_image']); // Change status to permanent. $file->status = FILE_STATUS_PERMANENT; // Save. file_save($file); file_usage_add($file, 'user', 'user', $user->uid); $apply_now_image_path = file_create_url($file->uri); variable_set('rgit_apply_now_image', $apply_now_image_path); variable_set('rgit_apply_now_image1', $file->fid); } }

But it didn't give correct answer. This is only work if the '#type' is managed_file'. It didn't work if the '#type' is media. Is any solutions there to upload images from media library.

phponwebsites

Exposed date filter adds a timezone offset in query

3 days 1 hour ago

In Drupal 8, when creating a view with an exposed filter on a Date field (which is in date only mode), the resulting query removes some hours based on my timezone.

I'm in the UTC+2 timezone, so a date filter of 2016-04-20 creates a query of DATE_FORMAT('2016-04-19T22:00:00', '%Y-%m-%d'). And so, none of the nodes I want are displayed...

How to avoid that?

Toni Fisler

Submission handler for the user registration form doesn't work

3 days 2 hours ago

I'm working on a Drupal 7 portal. I added a custom field to the registration form and I would like to get hold of custom field value when the registration form is submitted and before it is stored in the database.

I'm trying to use the submission handler for the registration form and print the content of $form and $form_state, but those values never get printed as message. I installed the Devel module as well.

function user_register_form_submit($form, &$form_state) { drupal_set_message('<pre>'. print_r($form, 1) .'</pre>'); drupal_set_message('<pre>'. print_r($form_state, 1) .'</pre>'); drupal_set_message(t('An info message from user_register_form_submit'), 'error'); }

I appreciate any input on what the issue could be.

Drupal7User

create a custom form based on user fields

3 days 3 hours ago

I created new menu item witch I want to insert a custom form to edit some user fields :

$items['user/%user/edit-custom'] = array( 'title' => 'Knowladge', 'page callback' => 'drupal_get_form', 'page arguments' => array('user_profile_form_custom', 1), 'access callback' => 'user_edit_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); return $items;

Then the custom function that return the form :

function user_profile_form_custom(){ module_load_include('inc', 'user', 'user.pages'); global $user; $user = user_load($user->uid); $form = drupal_get_form('user_profile_form', $user, 'account', 'custom'); return $form; }

When visiting "user/%user/edit-custom" page I can see the profile page, then with some logic code in hook_form_alter I can hide some fields and show up only needed fields...

But the problem that I can't save the form, I get this error :

Fatal error: Call to undefined function user_profile_form_validate() in path_to_drupal/includes/form.inc on line 1514

this solution is inspired from answers described in this post .

Have you any idea please how to solve this, or if you have another way to get some user fields, edit them in a custom page, and save the changes.

Thanks in advance.

Boussetta moez

Use a custom template field even if it's excluded from display

3 days 4 hours ago

In a Views, I have two field :

  • Link field : With 1 to n links to display (excluded from display)
  • Body field : Who use the previous link field (via rewrite output and token)

I have created a custom template for display link field like I want.

Here is my problem: When I render my Views, my custom template isn't used for display my links... He use the display function defined in the link field settings.

Is there a way to force View to use my template ? Any suggestions to do this?

Edit : Some screenshot of fields and theme informations

Link field :

Body field :

Theme Infos :

Payou

How to add programmatically region's class when region had block?

3 days 4 hours ago

I have one row with three column region. How can I add a custom class on each region when one of region is not used?

With three regions, the class is col-sm-4; with two regions, the class is col-sm-6; with only a region, the class is col-sm-12.

I use the following code in page.html.twig. It worked for me, but not with a single column.

{% if page.region_1 and page.region_2 %} <div class="row"> <div class="region_1 col-sm-6"> {{ page.region_1 }} </div> <div class="region_2 col-sm-6"> {{ page.region_2 }} </div> </div> {% endif %} {% if not page.region_1 and page.region_2 %} <div class="region_2 col-sm-12"> {{ page.region_2 }} </div> {% endif %} {% if not page.region_2 and page.region_1 %} <div class="region_1 col-sm-12"> {{ page.region_1 }} </div> {% endif %}

I'm try to use hook_preprocess_region().

function MYTHEME_preprocess_region(&$variables) { // Add class in header region. $region = $variables['elements']['#region']; $region_header = array( 'region_1', 'region_2', 'region_3' ); if (in_array($region, $region_header)) { $variables['attributes']['class'][] = 'col-sm-12'; } }
lwinkyawmyat

Displaying Webforms on Content Types in Page Manager/Panels

3 days 4 hours ago

The Webform module allows for a webform to be attached to each Content Type of the site. I can "Enable webform functionality" on my Page and Blog Content types and don't need to use a separate "webform" content type, very cool! This works great with Entity View Mode displays.

However, when using the Node Template in Page Manager, I can't get the Webform to render after adding the "Node being viewed" Webform element.

My goal is to use Page Manager to display every node, with the possibility of a unique webform attached to that node.

I brought this up at a meetup recently and was advised that it may be a bug. But I didn't think to ask where! So, if you think I should bring this up in an issue queue, where do you think that would be, Webform, ctools, or Panels?

Thanks, Jim

thejimbirch

How to use curly braces in schema default value?

3 days 5 hours ago

I have a long varchar field that I'm using to save serialised data with drupal_write_record. I'd like to set the default value of the column to "a:0:{}" (which is serialize(array())).

However, when Drupal runs database updates, they are run through the update_sql() function which includes the default value in the query. This means that the '{' and '}' are interpreted as prefixing table names and removed, leaving the actual value of "a:0:" in the database, which is not what I want.

Is there a way to use curly braces in a field spec's "default" value?

Matt Connolly
Checked
9 hours 18 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed