Hey this is my first issue/patch not sure if I am doing it right or not.

Currently in D8 I could not find a way to style the flag with an image. The flag when clicked would not supply me with anything I could use, and I was stuck either using some janky javascript to check the text and add my own Css class, or edit the AJAXactionLink file and add my own class based on the action of the flag.

 /**
   * {@inheritdoc}
   */
  public function buildLink($action, FlagInterface $flag, EntityInterface $entity) {
    $render = parent::buildLink($action, $flag, $entity);
    $render['#attached']['library'][] = 'core/drupal.ajax';
    $render['#attributes']['class'][] = 'use-ajax';
    $render['#attributes']['class'][] = $action; /**Adding This line enabled me to style the flag **/
    $render['#url']->setRouteParameter('_format', 'json');
    return $render;
  }

Adding the above line allowed me to implement my own style for the flag.

Comments

Tyler_Marshall created an issue. See original summary.

joachim’s picture

Status: Patch (to be ported) » Active
Issue tags: -Style Flag

I think there's already an issue for adding a template for the flag link -- can you check please?

(BTW: please don't use tags for adding random keywords or duplicating any other fields.)

socketwench’s picture

Status: Active » Closed (duplicate)
Related issues: +#2463365: Implement theming for flag link

Closing as this is a duplicate.