Commit ad9750c1 authored by Daniel Pepin's avatar Daniel Pepin
Browse files

Issue #2536510: Setup toolbar links/tray.

parent f7d84ed2
Loading
Loading
Loading
Loading
+18 −0
Changes for css/shopify.toolbar.css: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* Format inline links. */
#toolbar-item-shopify-tray.toolbar-tray-horizontal .toolbar-menu li {
  display: inline-block;
  margin: 0;
  border-left: 1px solid #ccc;
}

/* Special handling for the last link which goes to API Settings. */
#toolbar-item-shopify-tray.toolbar-tray-horizontal .toolbar-menu li:last-child {
  float: right;
  border-left: none;
}

/* Implement shopify icon image. */
.toolbar .toolbar-icon-shopify:before {
  background-position: center 8px;
  background-image: url('../images/shopify-toolbar-icon.png');
}
+21.3 KiB
Loading image diff...

shopify.install

0 → 100644
+1 −0
Changes for shopify.install: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
<?php

shopify.libraries.yml

0 → 100644
+5 −0
Changes for shopify.libraries.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
shopify.toolbar.css:
  version: 1.x
  css:
    theme:
      css/shopify.toolbar.css: {}
+89 −0
Changes for shopify.module: 89 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

//namespace Drupal\shopify;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
use Drupal\shopify\Entity\ShopifyProduct;
use Drupal\shopify\Entity\ShopifyProductVariant;
use Shopify\Client;
@@ -56,6 +60,91 @@ function shopify_cron() {
  }
}

/**
 * Implements hook_toolbar().
 */
function shopify_toolbar() {
  $items = [];
  $links = shopify_renderable_links();
  // @todo: Need caching per user setup.
  // @todo: Need better permission checking.
  $items['shopify'] = array(
    '#type' => 'toolbar_item',
    'tab' => array(
      '#type' => 'link',
      '#title' => t('Shopify'),
      '#url' => Url::fromRoute('shopify.admin'),
      '#attributes' => array(
        'title' => t('Shopify'),
        'class' => array('toolbar-icon', 'toolbar-icon-shopify'),
      ),
    ),
    'tray' => array(
      '#heading' => t('Shopify admin pages'),
      'shopify_links' => array(
        '#theme' => 'item_list',
        '#items' => $links,
        '#attributes' => array(
          'class' => array('toolbar-menu'),
        ),
        '#attached' => array(
          'library' => array(
            'shopify/shopify.toolbar.css',
          ),
        ),
      ),
    ),
    '#weight' => -5,
  );

  return $items;
}

/**
 * Returns an array of Shopify admin links.
 */
function shopify_renderable_links() {
  // @todo: Need better permission checking.
  $links[] = array(
    '#type' => 'link',
    '#title' => t('Overview'),
    '#url' => Url::fromRoute('shopify.admin'),
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('Sync'),
    '#url' => Url::fromRoute('shopify.sync'),
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('Webhooks'),
    '#url' => Url::fromRoute('shopify.webhooks'),
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('View Products'),
    '#url' => Url::fromRoute('entity.shopify_product.collection'),
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('View Collections'),
    '#url' => Url::fromUri('internal:/admin/structure/taxonomy/manage/shopify_collections/overview'),
    // @todo: Make more dynamic.
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('View Tags'),
    '#url' => Url::fromUri('internal:/admin/structure/taxonomy/manage/shopify_tags/overview'),
    // @todo: Make more dynamic.
  );
  $links[] = array(
    '#type' => 'link',
    '#title' => t('API Settings'),
    '#url' => Url::fromRoute('shopify_api.admin'),
  );
  return $links;
}

/**
 * Sync Shopify products to the site.
 *