Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

5

Here's a way to alter the query for entity reference autocomplete. You can add an expression that returns the string length and then sorts by this. This way, if a string contains "DIS", and it sorts by the string length, it will start with 3, and the only item that contains the string and is of the shortest length that contains the string (3) is the exact ...


3

Categories or Paragraphs are just references when you create a node view. Thus when you use them in the fields (as output) they are not sortable but you can add a relationship to them and then their individual fields (like name, id etc) become sortable Here is an example with tags (on article content type) Added term relationship Taxonomy terms on node ...


2

As you said, node revision does not have hook implement for check access. So you need other way to resolved your problem. My way is alter existing services. Just following document, there is file my_module/src/MyModuleServiceProvider.php <?php namespace Drupal\my_module; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\...


2

Typically, I found the answer 10 minutes after posting! For anyone else, in your custom submit handler get the form object from the form state. $formObj = $formState->getFormObject(); You can then call submitForm() on the form object and pass the form and form state variables. $formObj->submitForm($form, $formState); Then finally just simply ...


2

In a preprocess hook (preferred): /** * Implements hook_preprocess_HOOK() for page.html.twig. */ function MYTHEME_preprocess_page(&$variables) { if (isset($variables['node'])) { $variables['image'] = $variables['node']->get('field_image')->first()->view('full'); } } Or in Twig: {{ node.field_image.0|view('full') }} To use |view ...


2

Your question appears to be somehow related to this issue, which is closed and fixed. That issue contains an image which looks like so: So check if the version of the Group module that you're using, includes the patch included in that issue. If you don't have it included, it's probably why you don't have a "group content type" translation option in /admin/...


2

One approach is to add page templates to your theme registry: function MYMODULE_theme_suggestions_page_alter(array &$suggestions, array $variables) { //Allow theming the site error pages $route_name = \Drupal::routeMatch()->getRouteName(); switch ($route_name) { case 'system.401': // Unauthorized Access. $error = 401; break; ...


1

Maybe have a look at affiliate systems to see if they can guide you in the direction of a solution, e.g. https://www.drupal.org/project/commerce_affiliate. The issue here is that you haven't defined what your actual end goal is - if you simply want to know what the 80/20 split of the sale value is, you can just use https://www.drupal.org/project/...


1

What I'd recommend is to simply preprocess the paragraph, get the "round image" Boolean, and use it to add a class to the paragraph. This should be just enough to style the responsive image accordingly. /** * Implements template_preprocess_paragraph__PARAGRAPH_TYPE. */ function MYTHEME_preprocess_paragraph__profile_card(&$variables) { // Get ...


1

Found this after 5 seconds of googling: https://www.drupal.org/project/color_field https://www.drupal.org/project/colorfield https://www.drupal.org/project/jquery_colorpicker The search query was: drupal color field. Choose one, add one color field per content type to the user entity type (users should be able to edit their profile), then retrieve the ...


1

Some of those php extensions (like php-curl) were included in the core php package for arch so maybe you just need to update php? Some, (Like php-mcrypt) are depreciated and have been removed from newer versions of php (php7.2+ iirc) what version of php are you using for drupal? You may have to set an earlier version of PHP for your Drupal and then ...


1

You can load the node and then fetch the paragraph targetid . Later you can load paragraph targetid and then get all attributes of the image. use Drupal\paragraphs\Entity\Paragraph; use Drupal\node\Entity\Node; $node = Node::load($nid); $paragraph_field = $node->get("field_paragraph")->getValue(); $paragraph = Paragraph::load($paragraph_field[0]['...


1

If it is correct, should I also include print media queries in the print.css file? It's correct, and there's no need for media queries in the CSS file. (Separately, I'm still trying to determine what else is supplying the print styles in my site, aside from the ones I'm adding intentionally. But I can confirm that the above annotation example works.)


1

You may work with this approach. The following code snippet for drupal 7. Create field C of type number. Hide the field C in add/edit content type form. /** * Implements hook_form_alter(). */ function yourModule_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'CONTENT_TYPE_NAME_node_form'){ $form['field_c']['#...


1

That information isn't stored against the file entity, its on the image field attached to your source entity (e.g. your node) So you could do something like: $node->my_image_field->alt $node->my_image_field->title and that would give you the alt/title


1

Found it in $context['form']['#parents']. This is an array that contains the keys of the parent widget. In my case it looked like [ 0 => 'field_pagebuilder', 1 => ___PARENT_INDEX___, 2 => 'subform', ] which allowed me to generate my CSS selector for the states API: $deltaParent = $context['form']['#parents'][1];


1

First of all try to take a look at the buildForm method in the UserPasswordResetForm class, it takes some parameters. So you must call getForm like this: \Drupal::formBuilder()->getForm('Drupal\user\Form\UserPasswordResetForm::class', $user, $expiration_date, $timestamp, $hash); This is the function docs, $user = User requesting reset. $...


1

You can use hook_ENTITY_TYPE_presave to do this, just call if (!$entity->getSubject()) { $entity->setSubject(''); } if it isn’t filled. Hope it makes sense.


1

Forms have a validate and submit function(s). Submit never runs unless all validation passes. So all you have to do is add a custom validation /* * Implements hook_form_FORM_ID_alter */ function mymodule_form_user_register_form_alter(&$form, FormStateInterface $form_state) { $form['#validate'][] = 'mymodule_registration_validate'; } /* * Custom ...


1

As with most things, I suggested testing it out on a development/test site before trying on the live site. It's likely that the specific set of contribs and the libraries they use will affect the success of this operation. How did you install the modules? Do you use a composer workflow? In general, some paths stored in different places are going to be ...


1

Just because you're calling it a block-type of content it doesn't mean it will necessarily be the Block structure in Drupal. Using Paragraphs you can create such structures for your nodes, where editors will be able to choose and reorder different types of paragraphs you have set up for them. You can think of Paragraphs as Blocks to be inserted/reordered ...


Only top voted, non community-wiki answers of a minimum length are eligible