<?php

namespace Drupal\materio_simplenews\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;

/**
 * Defines dynamic local actions.
 */
class DynamicLocalActions extends DeriverBase {

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Implement dynamic logic to provide values for the same keys as in example.links.task.yml.
    $newsletters = simplenews_newsletter_get_all();

    foreach($newsletters as $news){
      $this->derivatives['materio_simplenews.' . $news->id] = $base_plugin_definition;
      $this->derivatives['materio_simplenews.' . $news->id]['title'] = $news->name;
      $this->derivatives['materio_simplenews.' . $news->id]['route_name'] = 'node.add';
      $this->derivatives['materio_simplenews.' . $news->id]['route_parameters']['node_type'] = 'simplenews_issue';
      $this->derivatives['materio_simplenews.' . $news->id]['route_parameters']['newsletter'] = $news->id;
      $this->derivatives['materio_simplenews.' . $news->id]['appears_on'] = ['view.simplenews_newsletters.page_1'];

    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}