This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

error with selecting language id

Hi,

I am trying to get the language id as follows:

$arg = "Sanskrit";

$languages = \Drupal::service('language_manager')->getLanguages();
foreach ($languages as $language) {
if ($arg == $language->getName()) {
$arg = $language->getId();

}
}

print_r($arg);exit;

It should print dv, since the Id for language Sanskrit is dv in my module. But it prints Sanskrit.

E commerce functionality Advice.

Hello Friends,

I have been tasked with adding eccomerce functionality to my Drupal 8 site.

Currently I am looking at the Commerce 2.x module to help me with achieving this. 

The problem I am currently facing is that I am required to store and query all content in a custom database and the Commerce 2.x module looks like it relies heavily on Drupals native database.

Some solutions I am considering are:

How do I display a pdf from a controller?

In Drupal 7 I did this in my page callback:

function ops_view_pdf() {
	$filepath = $_GET['file'];
	drupal_add_http_header('Cache-Control', 'private');
	drupal_add_http_header('Content-Type', 'application/pdf');
	readfile($filepath);
	return NULL;
}

How do I do this in Drupal 8?

Error in extracting zip files

I am facing an error in extracting audio files uploaded in zip format. The error is as follows- Argument 2 passed to Drupal\Core\Archiver\Zip::extract() must be of the type array, string given,  

The following is the code:

public function buildForm(array $form, FormStateInterface $form_state, $node = NULL) {

// REMOVED PARTS OF CODE FOR READABILITY

hook_boot in D8 using Event Subscriber

Hi All,

I want to execute an ajax request on page load in D8. (intention to execute some process on page load which I have done using hook_boot in D7, Now I am trying to achieve in Drupal 8.7.6)

I have used event subscriber (refered https://www.qed42.com/blog/porting-hookinit-drupal8). I have added mymodule.libraries.yml file where I have mentioned about JS file, I have included JS file via hook_preprocess hook in mymodule.module file. 

Redirect user when batch ajax encounters an error

I have a batch and when the operation is running and encountered

"An AJAX HTTP error occurred."

I want to redirect the user to another page and display the errors nicely. How can I do that with D8 batch? 

Thanks in advance!

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions