Drupal StackExchange

How can I set view permissions for content type to make it visible to autenticated users only?

1 day ago

I want a content type to be only visible to authenticated users.

Now the edit permission dialog only offers permissions for modification, not for displaying the published content.

Until Drupal 9, I've used the Permissions by Term module to limit public access for certain page areas and content types. Since Permissions by Term is not yet Drupal 10 compatible I had to remove it.

Is there an elegant, ideally Drupal 10 native way, to limit certain content types from public access?

david

hreflang links added to page source without translation

1 day 1 hour ago

When Interface Translation module is enabled in Drupal 8, I get hreflang links to ALL languages on the site for every page view sourse, no matter if the content is translated or not.

If alternate hrefland is active on all of the pages, even untranslated ones, it creates some SEO problems.

I want to remove these links. Is any Drupal way to do this?

latikas

Is there a function to get the system path for the current language?

1 day 2 hours ago

If I'm using multiple languages on the site with path prefixing, is there a quick way to get a system path for the current language?

For example, if the current language is English, and I'm interested getting the English path for 'user/password', what function call (or small number of lines) will return 'en/user/password'?

The following doesn't seem to work; it returns nothing:

drupal_lookup_path('alias', 'user/password', $language->language);
colan

Update the block through ajax

1 day 3 hours ago

I have added a block which shows the no of items added to an entity. I want to refresh the block through ajax as the items are added to an entity through ajax form so whenever I add an item, it will refresh or re-render the block content too.

I found some of the modules, but they are in Drupal 7 and not available for D8 so I want to make it done with my custom module but didn't find anything useful.

UPDATED

I have added the class attribute with the block and whenever I add any items, I made an ajax request through javascript which calls the respective controller and at the same time, I run this too--

// This is a part of the controller function from where I am calling below defined methods. $this->updateBlock(); protected function getBlock() { $block = $this->blockManager->createInstance('block_id', []); return $block; } public function updateBlock() { $block = $this->getBlock(); $this->response->addCommand(new ReplaceCommand('.block--class', $block->build())); return $this->response;

}

But It is not updating the block.

Ankit Jain

"File not found error" when installing using composer

1 day 5 hours ago

I'm running Docker on Ubuntu 18 with a container for MariaDB, Nginx and php-fpm (7.3).
The PHP container has composer installed, and I used it to create a Drupal Commerce project. I can start the Drupal install process using a browser, but after I input the DB settings, the process fails and I get the following error.

An AJAX HTTP error occurred.
HTTP Result Code: 404
Debugging information follows.
Path: /core/install.php?profile=commerce_base&langcode=en&id=1&op=do_nojs&op=do
StatusText: Not Found
ResponseText: File not found.

Increasing the execution time, post time, memory limit, post and upload sizes in the php.ini file, as recommended by another user, didn't solve the problem.

Nginx error log contains the following message.

[error] 6#6: *46 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream'.

The database has tables and data in it, so I know the database credentials are correct.

What am I doing wrong?

Robert

Allow user to fill out node form, then force registration

1 day 6 hours ago

I'm making a classified website.

Have a button that say "Make a ad" I would like the Anonymous user to be able to fill in the text for the ad.

But the Anonymous users after filling in advert. has to sign up for the ad to be posted

How can do this with drupal please?

many thanks for your help

Best Regards Charles

user3350619

Invalidating render cache items for anonymous?

1 day 7 hours ago

We have a certain content type in Drupal 8 that has a small grid of data on it that is populated from an API call when the node view is being built.

In that call, I am checking for cache and setting cache instead of talk to the API every request:

if ($cache = $this->cache->get($cache_key)) { return $cache->data; } // $content = request... $this->cache->set($cache_key, $content, REQUEST_TIME + 3600, ['mymodule']);

Where $cache_key is just mymodule:remote_id:subscription_id. My default cache bin is handled via Memcache.

The Drupal page cache time is set to 30 minutes, and Varnish sits in front of it for anonymous traffic.

I am noticing that even though my custom cache data is set for an hour timer, and the Drupal cache is set for 30 minutes, users are able to see data from 3 days ago but I am not sure how. As soon as I go view the site (authenticated) and refresh, the data updates.

I tried backtracking this but nothing jumped out as missing, perhaps other than some cache tags I might need to add. Even still, the render object is what is being shown from cache, which the data is a part of before it is cached, not the cached data item itself.

System cron is running every hour. Shouldn't it purge invalidated cache as part of system_cron?

Edit: I switched my local from Memcache back to the default cache (MySQL) and noticed render cache items all have an expiration of -1.

At what point are entity render cache items invalidated? I feel like that might be my issue, but not sure how to address it.

Kevin

Display success message after submitting form

1 day 7 hours ago

I am try to display an success message after submitting my form and redirect to next page. The code I am using is the following.

public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message(t('Form Submitted Successfully'), 'status', TRUE); }

It doesn't work for me.

Is there any alternate way to do it? What code should I use to display a success message?

Karthiga