Clean way to programmatically add attributes to a view field entity label link
Generate the scaffolding of a Views field plugin with Drupal Console

drupal generate:plugin:views:field


and put the link in the render() method generated by the command above:

  public function render(ResultRow $values) {
    if ($entity = $values-&gt;_entity) {
      return [
        '#type' =&gt; 'link',
        '#title' =&gt; $entity-&gt;label(),
        '#url' =&gt; $entity-&gt;toUrl(),
        '#attributes' =&gt; [
          'class' =&gt; ['foo'],
        ],
      ];
    }
  }


After clearing the cache you'll find the new field plugin when adding a field to the FIELDS list.