Score:0

How can I remove PDF download button?

lu flag

I am using the pdf_reader module and showing my PDF on the node. Now, I am supposed to hide the download button. For this purpose, I wrote the below javascript file:

jQuery(document).ready(function($) {
  document.querySelector('#download').style.display = 'none';
});

It's also in my theme's libraries.yml file. The last thing I did was write a hook_preprocess_node implementation and put in the below code:

  $node = \Drupal::routeMatch()->getParameter('node');
  if ($node->getType() == 'e_dergi') {
    $variables['#attached']['library'][] = 'conference_lite/custom';
  }

But I can't hide the download button for the life of me. What else should I try?

Score:0
pw flag

If your theme name is fluffiness in "fluffiness.info.yml" add following lines

libraries:
  - fluffiness/global-scripts

in your file "fluffiness.libraries.yml" add following lines

global-scripts:
  version: 1.x
js: 
  js/fluffiness.js: {} 

dependencies:
  - core/jquery
  - core/drupal

in your file "js/fluffiness.js" add following code

(function (Drupal, drupalSettings, once) {
   Drupal.behaviors.hideElement = {
     attach: function (context, settings) {
      jQuery("#download").hide();
     }
   }
 } (Drupal, drupalSettings, once));
Kartagis avatar
lu flag
Nope, didn't work :(
khurrami avatar
pw flag
Please check 1) file added on page using "View Page Source" 2) check any js error in browser
Kartagis avatar
lu flag
Page source doesn't include it, however an additional console.log says it's loaded.
khurrami avatar
pw flag
i think you should go through in detail, the way of adding js as mentioned here https://www.drupal.org/docs/theming-drupal/adding-stylesheets-css-and-javascript-js-to-a-drupal-theme look at this regarding cuddly-slider.js as they have explained in detail this might help you.
No Sssweat avatar
ua flag
@Kartagis Any JS errors in browser's console? Why not do it via CSS `#download { display: none; }`
Kartagis avatar
lu flag
@NoSssweat no JS errors in the console. Trying with CSS absolutely doesn't work :(
No Sssweat avatar
ua flag
@Kartagis is the custom CSS file being loaded? You can check with: Right mouse click >> inspect element >> network >> CSS and reload page. If it is, then try `#download { display: none !important; }`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.