Stack Exchange Network

Stack Exchange network consists of 175 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

4

In Drupal 8, private file permissions by default are given according to the entity to which they are attached. If the user has permission to view the entity, they will have permission to view the file. If you are not attaching the file to an entity, then you will need to implement hook_file_download(), where you will determine whether or not the user has ...


3

You are safe to use the same name. The fields are unique for each entity type, even when they have the same name. They have their own field storage configuration, instances and will be stored to dedicated database tables per entity type.


2

Yes short Answer have a look at creating a custom twig extension: the idea would be to pass the details required as an "exclude from display" field (or fields) to the custom global text field. Note excluded from display fields can be accessed in the "REPLACEMENT PATTERNS" section under view text. then basically in the text field you would do something ...


2

Files uploaded to managed files will be set as temporary. You need to set the file status as permanent, and add a usage, to prevent the file from being deleted. Setting files as permanent can be done using File::setPermanent(). File usages can be added as follows: $fid = 1; // The file ID $file = \Drupal\file\Entity\File::load($fid); $file_usage = \Drupal::...


2

In Drupal 8, timestamps (and created and updated) are stored as integers in the database. They do not use the native datatype. Timestamps can be added via the UI, but created and updated can only be used as basefields. Datetime and daterange fields are stored as ISO strings: date-only as Y-m-d and date+time as the full ISO8601 format (currently without ...


2

you can translate them easily in form_alter hook. This is one of charming Drupal features that I love. form_alter /** * Implement of hoo_form_later */ function YOURMODULENAME_form_alter(&$form, $form_state, $form_id) { if($form_id ='views_exposed_form' && isset($form['header']['node_bulk_form']['action']['#options'])){ foreach($form['...


2

There is a number of ways how to do it, check out this thread for a lot of suggested options: Change the '- Any -' text in an exposed taxonomy filter. You can change the themed output for that form and filter, you need a bit of custom code for that. You could use Better Exposed Filters module, it lets you override each option text: Use this field to ...


2

Your updated post shows the issue. The issue here isn't the form, it's the underlying storage method. You are using configuration, which is for site configuration, ie configure how the site as a whole works. But you want to save values per user, not for the whole site. What you are looking for is having a form used by all users, saving the submitted values ...


2

Make sure you don't call $node->save() in your presave, just update the time, the save will happen automatically.


2

hook_entity_presave() cannot save any entity, or saving an entity will cause hook_entity_presave() to be invoked again. If your hook_entity_presave() implementation isn't able to understand it is invoked for the second time, and saves again an entity, it will cause an infinite loop. Even if you implement hook_ENTITY_TYPE_presave() and save a different entity,...


1

The easiest way to go since you have mentioned business rules module: Create a rule: Entity is viewed Create a Variable Data Comparison to check if [current-user:url:path] equal to [user:url:path] If Yes, DO NOTHING If No, Create a Page redirect action to the home page. Hope it will help,


1

From a Drupal perspective, timestamp has issues with Views Filters. In a recent D7 project, I went with timestamp just to keep things consistent since I was doing custom module date field queries. In D7 I noticed that View filters only works if you enter a timestamp rather than a date, this is silly! Which makes me think most people use date, since it ...


1

Just thought it would be easier to show a basic example that has both parent and submenu item in the mymodule.links.menu.yml. Right now both links goto the same place (as I had to pick a default for the parent item, since I didn't have a admin page that lists all my custom links yet ... and also since having "route_name: <nolink>" did not work for ...


1

MYMODULE/src/Form.php: /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // get form config. $config = $this->config('MYMODULE.settings'); // Set our count. Used in for loop below. if (!empty($form_state->getValue(['fieldset', 'field_count']))) { // get $form_state count value. $...


1

It is also possible to do one-liner with magic method: $node->field_file->entity->getFileUri(); Or to render as string file_create_url($node->field_file->entity->getFileUri());


1

My issue was from improper checking of array key values. Below is the approach for non-ajax form adjustment (which is very similar to ajax). MYMODULE/src/Form.php: /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // get form config. $config = $this->config('MYMODULE.settings'); // Set our count. ...


1

You need to attach library in your hook_form_alter(): /** * Implements hook_form_alter(). */ function <YOUR_MODULE_NAME>_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){ /*Attach library, for Blazy implementation you will need $form['#attached']['library'][] = 'blazy/load'; */ $form['#attached']['...


1

use Change Label Length limit module. it lets users change the maximum limit of label fields.


1

As you are using an Apache server, you may try to set the Drupal root folder using an .htaccess file in your site_root: RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{REQUEST_URI} !web/ RewriteRule (.*) /web/$1 [L] (Replace example.com with your actual domain name.) This way, you ...


1

views_natural_sort is able to do this kind of sorting. It might be currently in alpha state but it already has more than 250 installation for the alpha 3 release which means that most major bugs should have already been ironed out. Upon enabling you are able to choose title to sort with and you are given 2 extra options for natural sorting (sort ...


1

I would use 2 entity reference field, one in each content type referencing the other. With some custom logic, you could add the desired behavior, eg remove reference Foo -> Bar when the user removes Bar -> Foo. Regarding the migation, you can run the first migration twice with the --update flag the 2nd time: Step 1. Migrate Foo. The migration_lookup plugin ...


1

Using this answer as a base you can add views_field_view to include a view of content filtered by term. In more details 1. Create a view of terms that includes count of content using each term Create a view that displays terms enable aggregation add relationship Content with term add sort content uuid with aggregation type: count (optional) add field ...


1

Drupal has very advanced Multi-lingual capabilities, so it's safe to assume that you can configure your site according to your needs. You just have to learn a bit about Drupal multilingual fundamentals and see how your needs fit in there. It seems your question is about how languages are selected and displayed, and not about Interface translation. You ...


1

Yes, it's possible to provide a custom search index for either the Core/Search API module. Both modules are using the D8 plugin API to create their own plugin types for providing new indexing. In Core, the SearchPlugin plugin type allows you to define the methods that you will need to implement for all aspects of search. To see how this works, look at the ...


1

You can check if the user is authenticated like so: For example, I have created the following function in themename.theme. # Function to get user logged info function tropical_preprocess_page(&$variables){ // if user is authenticated if($variables['user']->isAuthenticated()){ # gets username $user_logged_in_name = $variables['user']->...


1

Create custom EventSusbcriber ( read this for more information ) then check if the current theme is seven with and MODULE_NAME is enabled $moduleHandler = \Drupal::service('module_handler'); if (\Drupal::service('theme.manager')->getActiveTheme()=='seven' && $moduleHandler->moduleExists('MODULE_NAME')){ then try to uninstall with ...


1

Something like the following could help you. Just Set $filepath and $filename with your desired values. $filepath = "/path/to/my/image/chart.png"; $filename = "chart.png"; $response = new Response(); $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename); $response->headers->set('Content-...


1

This feature does not exist in core yet but it is in progress right now. Look for it in Commerce 2.13.


1

There is a new easy alternative to display icons in Menu Items in Drupal 8: The Menu Manipulator module now provides an option for you to create a list of available icons that editors can select when editing menu links. The icon's ID is then passed to Twig so you can theme/render/display it however you want (e.g. an icon font such as FontAwesome, a custom ...


1

To get a field with the field name stored in the variable field you can use the method get() on the node: {{ node.get(field).value }}


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