0

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?

1 Answer 1

1

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"]);

    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.