You are here

public function CampaignMonitorCampaignController::draftsOverview in Campaign Monitor 8

File

src/Controller/CampaignMonitorCampaignController.php, line 87

Class

CampaignMonitorCampaignController
Campaign Monitor Lists controller.

Namespace

Drupal\campaignmonitor\Controller

Code

public function draftsOverview() {
  $content = [];
  $drafts_admin_url = Url::fromUri('https://waxeye.createsend.com/subscribers/', [
    'attributes' => [
      'target' => '_blank',
    ],
  ]);
  $drafts_empty_message = t('You don\'t have any drafts configured in your
      Campaign Monitor account, (or you haven\'t configured your API key correctly on
      the Global Settings tab). Head over to @link and create some drafts, then
      come back here and click "Refresh drafts from Campaign Monitor"', [
    '@link' => Link::fromTextAndUrl(t('Campaign Monitor'), $drafts_admin_url)
      ->toString(),
  ]);
  $content['drafts_table'] = [
    '#type' => 'table',
    '#header' => [
      t('Name'),
      t('Author'),
      t('Created'),
      t('Link'),
    ],
    '#empty' => $drafts_empty_message,
  ];
  $cm_drafts = campaignmonitor_campaign_get_drafts();

  // $total_webhook_events = count(campaignmonitor_default_webhook_events());
  foreach ($cm_drafts as $key => $cm_campaign) {

    // $details = campaignmonitor_get_list_details($key);
    //      $stats = campaignmonitor_get_list_stats($key);
    $content['drafts_table'][$key]['name'] = [
      '#markup' => $cm_campaign['Name'],
    ];
    $content['drafts_table'][$key]['author'] = [
      '#markup' => $cm_campaign['From'],
    ];
    $content['drafts_table'][$key]['sent'] = [
      '#markup' => $cm_campaign['Created'],
    ];
    $content['drafts_table'][$key]['link'] = [
      '#type' => 'link',
      '#title' => 'Preview',
      '#url' => Url::fromUri($cm_campaign['Link']),
    ];
  }
  $refresh_url = Url::fromRoute('campaignmonitor.refresh_drafts', [
    'destination' => 'admin/config/services/campaignmonitor/drafts',
  ]);
  $content['refresh'] = [
    '#type' => 'container',
  ];
  $content['refresh']['refresh_link'] = [
    '#title' => 'Refresh drafts from Campaign Monitor',
    '#type' => 'link',
    '#url' => $refresh_url,
  ];

  // $create_url = Url::fromRoute('campaignmonitor.list_create_form', array('destination' => 'admin/config/services/campaignmonitor/drafts'));
  //
  //    $content['create'] = array(
  //      '#type' => 'container'
  //    );
  //
  //    $content['create']['create_link'] = array(
  //      '#title' => 'Create a new list',
  //      '#type' => 'link',
  //      '#url' => $create_url
  //    );.
  return $content;
}