Score:0

Disabling Flag link access on view

ru flag

I have a custom entity displayed in a view. If some field is of a certain value, the Flag link should not be available and replaced by some text.

function my_module_preprocess_flag(&$vars){
  $f = \Drupal::service('flag.link_builder');
  if ($vars["flaggable"]->field_my_field->getValue() != null) {
    if ($vars["flaggable"]->field_my_field->getValue()[0]["value"] == "0") {
      $link = $f->build('flag', $vars['flag']->id(), 'buy');
      $link["#access"] = FALSE;

    }
  }
}

Nothing seems to happen.

What could be the solution here?

Score:1
ru flag

I managed to disable the link by changing my function.

function my_module_preprocess_flag(&$vars){
  if ($vars["flaggable"]->field_my_field->getValue() != null) {
    if ($vars["flaggable"]->field_my_field->getValue()[0]["value"] == "0") {
      $vars["title"]["#markup"] = "New text";
      unset($vars["attributes"]["href"]);

    }
  }
}
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.