Secondary Tabs and views

1 month 3 weeks ago

I am trying to get Secondary Tabs to work. I want to create a local tab with sub tabs.

View | Edit | Reg Report

Reg Report
    Reg Report | Pre-Registration | Post-Registartion (Secondary Tabs)

I tried this method (Menu secondary tabs) and have it showing the naviagation, however when I add the path for Photo to my second view the navigation goes away.

Here is the code:

/** * Implements hook_menu(). */ function secondary_tabs_menu() { $items['node/%node/update'] = array( 'title' => 'Update', 'page callback' => 'price_callback_function', 'access arguments' => array('access args'), 'type' => MENU_LOCAL_TASK // This adds the 'Update' tab to the node path ); $items['node/%node/update/price'] = array( 'title' => 'Price', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['node/%node/update/photo'] = array( 'title' => 'Photo', 'page callback' => 'callback_function', 'access arguments' => array('access args'), 'access callback' => TRUE, 'type' => MENU_LOCAL_TASK // This adds another tab under 'Update' ); return $items; } /** * Implements hook_admin_paths(). * * Show admin theme on the participants totals report. */ function secondary_tabs_admin_paths() { return array( 'node/*/update' => TRUE, ); }

My goal is to create a sub-section where I can click through a few views within this secondary tab area.

Also, I was trying to add the Admin theme to the views as well.I have it in code but it doesn't seem to work.

Can someone guide me towards what I might be missing. Thanks!

timwhelan

Failure getting nodes from terms via the rest api

1 month 3 weeks ago

I have added a REST web service in Drupal and all content is tagged with taxonomy. I'm now trying to acquire all related nodes to the terms.

First I'm calling taxonomy_vocabulary/getTree along with the vid and I'll get all the terms for a specific vocabulary, that works just fine. The problem comes when I've gotten all the term-id's I need to go through. When I create a request it fails to find the nodes that should be connected to the term. I'll get a 404 response on each request.

This is how I call the selectNodes. I'm creating a POST request and pass along with the tid, the endpoint is called http://myhostname/api/taxonomy_term/selectNodes

Have someone else experienced this? Do I need to pass more arguments with the POST call?

EDIT: After a quick look in wireshark it also returns the error string: "String value: No nodes were found with tid 15". Does this mean that there aren't any relation between the terms and the nodes by default?

David Wiktorsson

Create file through services

1 month 3 weeks ago

I've been trying to create and update users and their pictures through REST calls using the services module. So far, I've got creating and updating users to work, but creating files to set their profile pictures still doesn't work.

I try to do a POST request to my API endpoint (http://www.domain.com/api/api_name/file), with the following data:

$data = array( 'file' => base64_encode($file), 'filename' => $filename, 'filepath' => 'public://' . $filename );

I POST this using CURL, with the exact same settings (apart from the API endpoint) as I'm using to create a user, which is working. However, I'm getting a HTML 500 as a response, with no response contents otherwise. The following error is logged in the Drupal error log:

Notice: Undefined property: stdClass::$fid in file_entity_access() (regel 1661 van /home/enschede/domains/aegee-enschede.nl/public_html/sites/all/modules/file_entity/file_entity.module).

The function that it errors on, file_entity_access, says that its $file parameter will either be an object, or a string with the file type (e.g. "image") if it is a create action. Apparently, it receives an object, so the create action is not executed properly on the server.

However, at this point I'm stuck. I can't find where these calls are coming from on the server, and I can't find anything I should change in the POST request. The fields I'm posting are the same as a tutorial I've followed. I'm posting the following fields to create a user, with the exact same CURL options otherwise:

$initialData = array( 'name' => 'test.user', 'mail' => 'bogus_email@provider.com', 'pass' => 'waytoolongboguspassword', 'status' => 1 );
Erik S

Retrieving value of paragraph type with entity reference revision through preprocessor

1 month 3 weeks ago

I have created a paragraph type which has field of type entity reference, link, plain text.

Now I want to fetch the values present in these through the preprocessor.paragraph.inc and display it in the custom template(twig).

Can anyone please let me know how do i do this?

I have written a hook function in the preprocessor, but unable to fetch values of paragraph types.

Eg of my paragraphs type:

  1. Section
  2. Box

In the section contains 2 fields, first is the title which is a plain text and second is the box, which is an entity reference revision

The box, is a paragraph type which has many fields like

  1. Link
  2. Image
  3. text field
  4. Wysiwig

Now how do i access values present in these through the hook function and display the same in twig template.

Guruprasad

Dynamic menu item based on Views argument

1 month 3 weeks ago

Is it possible to have a dynamic title on the menu item based on the argument that Views is receiving? I'm using the title on the menu item on the breadcrumb and my breadcrumb changes based on the argument.

Luiz Guilherme

Force users to always log in and show no content

1 month 3 weeks ago

I am using Drupal 7.31 and I installed the MD Alpine theme. I have a site which loads a video on the front page. I want to hide this front page. When users come to my site, I want them to be redirected to the login form.

I tried changing the home page to /user and that was a huge mistake. I did manage to undo this. I also went into the permissions and removed any permission for the anonymous user, including the permission to view published content.

I know I have seen this question before, and it seems like there might be a module that can fix that. I am willing to make some configuration change.

tjholmes66

File Transfer failed, reason: Unable to change to directory

1 month 3 weeks ago

I'm work on updates modules in my drupal site. When i access localhost/authorize.php after linked in config, i recieve this:

Update failed! See the log below for more information. Your site is still in maintenance mode.

the log is...

views Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/views views_bulk_operations Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/views_bulk_operations webform Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/webform jquery_update Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/jquery_update simplenews Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/simplenews entityreference Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/entityreference ctools Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/sites/all/modules/ctools entity Error installing / updating File Transfer failed, reason: Unable to change to directory /drupal/sites/all/modules/entity

I have tried to fix permissions in folder using: sudo chmod a+w and sudo chown root sites/default and chmod 777 , every using folder sites/default and sites/all/modules, but i canot successfuly updates my modules using ftp and automatic.... how i fix this? thanks in advance

Matheus Silva Itep

Display content based on URL

1 month 3 weeks ago

I am working on Drupal 8. I have a to display content from a content type on different pages. I am trying to use Views to achieve this.

In the content type I added a field to refer to Pages so that I can create relation between content of content type and Pages (another content type). Basically its like tagging content with page name.

I want to display content from content type created on those pages tagged in the content. I am not able to achieve using views.

Any ideas how this can be done? I have tried contextual filter and relationship but none works.

Thanks

Deva

Upload External File to Drupal File System

1 month 3 weeks ago
Situation

I would like to be able to upload files programmatically from an external source to the drupal file system. I was thinking of making a RESTful API that allows me to save external files into my site's public file path. The file is an excel file as well if that changes anything.

Problem

Currently, I am thinking of just using an S3 bucket to store the external files. Then within my site, I would simply run a GET REQUEST and programmatically save the file. I was just hoping there was a way to simply POST a file in drupal without me having to use Amazon's S3.

Parameters:

  • Drupal Version 8.8
  • Drupal Site BackEnd= PHP 7.3
  • External App FrontEnd = Vue.js
  • External App BackEnd = .NET Core
  • Required File Type: .xlxs
  • Secondary File Types: .csv, .docx, .json, .jpeg, .mp4, .txt
TL;DR

How can I make it so another site/app can upload files to my site? (using JavaScript)

Notice: I understand StackOverflow is only meant for help with code issues but I would greatly appreciate some help getting started and if not at least some very useful links that are credible. Some of the research I have found is not useful seeing that I am on Drupal 8.8

B. Cratty

How to pipe output of "drush sql-dump" without warnings

1 month 3 weeks ago

When I do: drush sql-dump > somewhere/database.sql if there will be any warnings printed by Drush, they will be included at the beginning of the created database.sql file. Can we avoid it somehow?

I know there is the --result-file= option that ignores all warnings when creating the file, but is there any way to ignore warnings when piping the output? I would like to parse the output before actually saving it into a file if its possible.

drush 8

Łukasz Zaroda

Upload Nodes with Image Fields

1 month 3 weeks ago

I'm using jquery mobile and phonegap for a mobile app. I have uploaded an image file and received the fid but the subsequent request to create a node and attach the fid fails. The node is created although the image field is not filled in with the fid. Also the uploaded image in ../sites/default/files doesnot have dimensions(height and width).

Post the image:

var filedata = { "file":{ "file":imageObj['base64s'][0], "filename":imageObj['names'][0], "filepath":"public://"+imageObj['names'][0], "mimeType":"image/"+imageObj['names'][0].split(".")[1], "filesize": imageObj['sizes'][0] } }; $.ajax({ url: localStorage.appurl+"/api/file.json", type: 'post', data: filedata, dataType: 'json', cache: false, headers: { 'X-CSRF-Token': localStorage.usertoken }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log('error '+errorThrown); d.reject(errorThrown); }, success: function (data) { d.resolve(data); } });

Create the node:

$.ajax({ url: localStorage.appurl+"/api/node.json", type: 'post', data: "node[title]=new node&node[type]=ftritem&node[field_ftritem_images[und][0][fid]=7895", dataType: 'json', heders: { 'X-CSRF-Token': localStorage.usertoken }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log('error '+errorThrown); }, success: function (data) { console.log("Node created"); } });

Im getting this error:

Notice: Undefined offset: 0 in image_field_widget_form() (line 358 of /var/www/dt11/modules/image/image.field.inc).

Notice: Undefined offset: 0 in file_field_widget_form() (line 526 of /var/www/dt11/modules/file/file.field.inc).

Has anyone faced this before ? Any suggestions are highly appreaciated.

david

How to send email to submitter in a webform?

1 month 3 weeks ago

I have a webform and i want to send by mail this webform to submitter. For the moment, i created an hidden field with token [current-user:mail] and i chose this field in adress. I think it isn't very well. Can I do it in hook_form_alter ? if yes, how to do it?

cel57

How can I trigger a Drupal Core action without writing any PHP code?

1 month 3 weeks ago

On my D8 site I have configured an action of type "Send email" using the Drupal Core "Actions" module (module can be installed under "Administration > Extend"). I want this Drupal Core action to trigger when a new comment is submitted.

In D7 there was another Drupal Core module named "Trigger" which allowed me to configure the desired trigger. In D8 there's no longer a "Trigger" module, nor can I find any other means to configure any Drupal Core action triggers. In the D8 docs I have found this not-very-helpful paragraph:

In D7, there are triggers defined, supporting the core Trigger module. This is not supported in D8.

My general question therefore is: How can I configure a D8 site to trigger an action that was defined via the Drupal Core module "Actions" when a certain event occurs? Specifically in my case: How can I trigger a "send email" action when a comment is submitted?

As the title of this question mentions, I don't want to write PHP code to achieve this. I am willing to install a stable third-party module, though, as long as it cooperates with the Drupal Core "Actions" module.

In a wider sense, I am trying to understand what the Drupal Core "Actions" module does. To me, the module seems to be quite useless if as a site admin I cannot configure triggers for its actions.

herzbube

Set default "Quantity" dropdown select in product. Commerce Kickstart

1 month 3 weeks ago

Using the Commerce Kickstart distribution I have a shop site listing products. The product page shows a Quantity widget to allow the buyer to choose the product quantity to be added to the cart. (look my capture)

I need to change this widget to the standar select list html element. (look the capture)

Update: I found the library which generate this "spinner", is located at: profiles/commerce_kickstart/libraries/jquery_ui_spinner I don't see any module related to this. Maybe in theme?

chefnelone

New to Drupal 10.2.4. Looking to Consume RESTful data, and populate content on page. Most articles seem outdated or so far, don't give clear answer [closed]

1 month 3 weeks ago

Given JSON response from external API like this: { "Id": "Dr1", "DoctorInfo": { "firstName": "Donald", "lastName": "Duck" }, "PatientList": [ { "Id": "Pt1", "Name": "Patient 1", "AppointmentDate": "04/01/2024" }, { "Id": "Pt2",
"Name": "Patient 2", "AppointmentDate": "04/02/2024" } ] }

What modules/content type, php code, etc. would I use. I thought this would be a no-brainer.

Corey Baker

Add custom ajax command to ajax response after webform is submitted

1 month 3 weeks ago

What I'm trying to do is to invoke some javascript after a webform is successfully submitted by ajax.

To do that I followed this advice and created an EventSubscriber to intercept ajax response and add my custom command there. The problem is that on some reason I can't check if the webform is submitted (data are sent) or not.

public function onResponse(FilterResponseEvent $event) { if($event->getResponse() instanceof WebformSubmissionAjaxResponse && $event->getResponse()->getWebformSubmission()->isCompleted()) { $event->getResponse()->addCommand(new MyCustomCommand()); } }

The problem is in isCompleted() method which always returns false on some reason. Actually I checked other methods from WebformSubmissionInterface and in this my event subscriber this WebformSubmission entity always looks empty (getters return nothing) and geState() always returns "STATE_UNSAVED" not depending if a webform is successfully sent of failed on validation.

What I'm missing? Is anything I'm doing wrong here? Or maybe are there any other method to achive same goal?

john

custom module to create multiple forms with pop-ups

1 month 3 weeks ago

I am working on a custom module to create a form. Functionality of the module is as follows: The first form has an url, on clicking the url it should show another form as a pop-up. How can i call these forms in the hook menu. Does tools_js has any significance?

<?php function patient_menu() { $items['patient_add/mainpage'] = array( 'title' => 'New Patient', 'page callback' => 'patient_form', 'page arguments' => array(), 'access callback' => 'user_is_logged_in', 'type' => MENU_CALLBACK, ); //a link to add patient diseases $items['patient_add/%ctools_js'] = array( 'page callback' => 'patient_callback', 'page arguments' => array(1), 'access callback' => 'user_is_logged_in', 'type' => MENU_CALLBACK, ); return $items; } // a function to make a link function _patient_make_link($link_text = '') { return '<div id="patient">' . l($link_text, 'patient_add/nojs', array('attributes' => array('class' => 'ctools-use-modal'))) . '</div>'; } //first form function patient_form($form, &$form_state) { ctools_include('modal'); ctools_modal_add_js(); $form['p_name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); $form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#size' => 30, '#maxlength' => 30, '#required' => TRUE, '#attributes' => array('placeholder' => t( 'in Years' )), ); $form['submit'] = array( '#value' => t('Add Patient'), '#type' => 'submit', ); _patient_make_link('add disease details'); return $form; } //Ajax menu callback function patient_callback($ajax) { if ($ajax) { ctools_include('ajax'); ctools_include('modal'); $form_state = array( 'ajax' => TRUE, 'title' => t('disease details'), ); $output = ctools_modal_form_wrapper('disease_form', $form_state); if (!empty($form_state['ajax_commands'])) { $output = $form_state['ajax_commands']; } print ajax_render($output); drupal_exit(); } else { return drupal_get_form('disease_form'); } } //second form function disease_form($form, $form_state){ $form['disease_ids'] = array( '#type' => 'select', '#title' => t('Disease IDs'), '#multiple' => TRUE, '#options' => array( 'Cancer' => 'Cancer', 'Dengu' => 'Dengu', 'Viral Fever' => 'Viral Fever', 'Malaria' => 'Malaria', ), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } function patient_form_submit($form, &$form_state) {}
ana

Setup custom required field validation for a field in custom form

1 month 3 weeks ago

How can I setup custom required field validation message for a text field in my custom form. I tried below code. But it is not working. It always showing 'Please fill out this field'.

$form['first_name'] = [ '#type' => 'textfield', '#title' => $this->t('First Name'), '#default_value' => $this->store->get('first_name') ? $this->store->get('first_name') : '', '#required_but_empty' => $this->t('Please enter First Name'), '#required' => TRUE, ];
Cool
Checked
8 hours 46 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed