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

Creating a node by code: Where to place the code.

I am trying to create a custom module to createa new node programatically. I believe this short and sweet code snippet will do it.

$node = \Drupal::entityTypeManager()->getStorage('node')->create([
   'type'  => 'page',
   'title' => 'This is the Title',
   'body'  => 'Some text in the body.',
]);
$node->save();
\Drupal::messenger()->addStatus(t('The page has been created.'));

But where in my custom module do I place this code? Should it be a Plugin, a Controller, a Service, or what?

Dynamic Access Control Subscriber Service

I need to insure a user didn't modify a url in their browser to access information he or she is not supposed to have access to. The url paths I'm monitoring is /users/123. "/users/123" is the path to a view with a contextual filter. I want to prevent the user from changing 123 to something else and viewing and editing another user's information. 123 is an id that is in a custom field in their user profile set by an administrator. 

I'm trying to do this with a service as follows:

Create sections on same page with views

With views is it possible to create multiple sections of same content type on the same page? I want to have them assigned with section URLs like "#SECTION1" , "#SECTION2" etc. So on the same page when I click on a link mysite.com/#SECTION1 it should gothe section correctly.Isthere a way to get these sections created using Drupal view?

Detect is form modal

Hi, is it possible to detect is form created as modal ('data-dialog-type' => 'modal') or not(simple by link) ?

Thanx in advance
marukas

Enforcing 'UniqueField' contraint when field is created programatically

Normally, you can addConstraint('UniqueField') to ensure that the title field of a node is unique.

However, in my use case, the title field is hidden in the form display (so it is empty), and instead, I create the title field by joining two other fields (using hook_node_presave()). Then, setting the 'UniqueField' constraint for the title field has no effect.

Filter view result column

I have a view that yields result in Table format. The view result looks as below:

https://imgur.com/a/Os1MFYb

Is there a way to add column-level filters as highlighted in the image? The filters should be added to each column after the view results are rendered based on exposed filters. Is there a way to achieve this?

Pages

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