Commit bee70564 authored by Vladimir Roudakov's avatar Vladimir Roudakov
Browse files

Issue #3294203: Coding standards: 4.x

parent 4ced5806
Loading
Loading
Loading
Loading

AUTHORS

deleted100644 → 0
+0 −6
Original line number Diff line number Diff line
AUTHORS

Andrew Dekker <@simultech>
Deji Akala <@dejiakala>
Gabriele Maira <@gambry>
Ben Hoad <@benhoad>
 No newline at end of file
+9 −22
Original line number Diff line number Diff line
@@ -9,29 +9,16 @@ stories on a Drupal website.

- Install Drupal module.

## Configuration
## Configuration (version 4)

- Login to [shorthand account](https://shorthand.com/signin) and
  [generate API key](https://support.shorthand.com/en/articles/62-programmatic-publishing-with-the-shorthand-api).

- Create a new input format that supports HTML by visiting page `/admin/config/content/formats`, or use an existing one (Full HTML)

  - Ideally for this we want to avoid having filters adjusting the content.

- Visit configuration page at `/admin/config/content/shorthand` to add API key and other settings.
- Login to [shorthand account](https://shorthand.com/signin) and [generate API key](https://support.shorthand.com/en/articles/62-programmatic-publishing-with-the-shorthand-api).
- Visit configuration page at `/admin/config/services/shorthand` to add API key 
  and other settings.
- Visit syncronisation page at `/admin/content/shorthand` to download required 
  stories.
- Add shorthand field to desired entity (content type, taxonomy term or user).

## Usage

- Go to Content > Shorthand story list and add a Shorthand Story

The Story content will be added to the body of the entity, which by default
displays together with Name and Author when visiting the Story page.

You may want to alter the Display settings to hide the Title and the Author, as
well as alter the page display for shorthand stories in order to hide
everything but the story content itself. i.e. by changing the page.html.twig
file, or through the Context contrib module creating a context for the stories
pages.

There are several ways to display the story as a full page, just use the one
who best suits you.
- When editing / managing entity with Shorthand field, select one of the 
- downloaded stories.
+1 −1
Original line number Diff line number Diff line
@@ -7,4 +7,4 @@ package: Other
dependencies:
  - drupal:text

configure: shorthand.admin_settings_form
configure: shorthand.settings_form
+1 −2
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ function shorthand_update_8002() {
}

/**
 * Add field for external asset hosting - boolean
 * Add field for external asset hosting - boolean.
 */
function shorthand_update_8003() {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
@@ -234,7 +234,6 @@ function shorthand_update_9001(&$sandbox) {
    ->save();
}


/**
 * Move shorthand token to different property.
 */
+48 −52
Original line number Diff line number Diff line
@@ -2,12 +2,10 @@

namespace Drupal\shorthand\Controller;

use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\Url;
use Drupal\shorthand\ShorthandApiInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -106,7 +104,7 @@ class RemoteCollectionController extends ControllerBase {

    foreach ($stories as $story) {
      unset($story['metadata']);
      //unset($story['image']);
      // unset($story['image']);.
      unset($story['api_version']);

      $url = $story['image'];
@@ -119,14 +117,12 @@ class RemoteCollectionController extends ControllerBase {
      ];
      $story['image'] = $this->renderer->render($image_variables);

      $apiService = 'shorthand_api';
      $updatedStory = \Drupal::service($apiService)->getStories();

      // $updatedStory = $this->shorthandApi->getStories();
      $title = $this->t('Download story');
      $type = 'link';
      if (in_array($story['id'], $localStories)) {

        $path = \Drupal::service('file_system')->realpath('public://' . static::SHORTHAND_STORY_BASE_PATH . '/' . $story['id'] . '/' . $story['updated']);
        $path = $this->fileSystem->realpath('public://' . static::SHORTHAND_STORY_BASE_PATH . '/' . $story['id'] . '/' . $story['updated']);
        if (file_exists($path)) {
          $title = $this->t('The story is up to date');
          $type = 'markup';
@@ -179,7 +175,15 @@ class RemoteCollectionController extends ControllerBase {
    ];
  }

  public static function downloadStoryBatch($sids, &$context) {
  /**
   * Download shorthand stories.
   *
   * @param array $sids
   *   List of shorthand stories IDs.
   * @param array $context
   *   Batch content configuration.
   */
  public static function downloadStoryBatch(array $sids, array &$context) {
    $message = 'Downloading story...';
    $apiService = 'shorthand_api';

@@ -193,7 +197,6 @@ class RemoteCollectionController extends ControllerBase {
    foreach ($sids as $sid) {
      $file = \Drupal::service($apiService)->getStory($sid, []);
      // ->getStory($sid, ['without_assets' => TRUE]);

      /*$external_file = 'https://www.example.com/test.png';
      $destination = 'sites/default/files/a-directory/test.png';
      $response = \Drupal::httpClient()->get($external_file, ['sink' => $destination]);*/
@@ -211,22 +214,26 @@ class RemoteCollectionController extends ControllerBase {
      $result = $archiver->extract($destination_path);

      // Update story.
      $updatedStory = \Drupal::service($apiService)->getStory($sid, []);
      $updated_uri = 'public://' . static::SHORTHAND_STORY_BASE_PATH . '/' . $sid . '/' . $updatedStory['updated'];
      /*$updatedStory = \Drupal::service($apiService)->getStory($sid, []);
      $updated_uri = 'public://' . static::SHORTHAND_STORY_BASE_PATH . '/' .
      $sid . '/' . $updatedStory['updated'];
      $updated_path = $file_system->realpath($updated_uri);
      // $file_system->move($destination_path, $updated_path);

      $public = PublicStream::basePath();
      $html = str_replace('./assets/', './' . $public . '/' . static::SHORTHAND_STORY_BASE_PATH . '/' . $sid . '/assets/', file_get_contents($destination_path . '/index.html'));
      $html_dom = Html::load($html);

      // Title tag.
      $title_dom = $html_dom->getElementsByTagName('title')->item(0)->firstChild;
      $html = str_replace('./assets/', './' . $public .
      '/' . static::SHORTHAND_STORY_BASE_PATH . '/' . $sid . '/assets/',
      file_get_contents($destination_path . '/index.html'));
      $html_dom = Html::load($html);*/

      /*// Title tag.
      $title_dom = $html_dom->getElementsByTagName('title')
      ->item(0)->firstChild;
      $title = $title_dom->ownerDocument->saveXML($title_dom);

      // Body tag.
      $body_dom = $html_dom->getElementsByTagName('article')->item(0);
      $body = $body_dom->ownerDocument->saveXML($body_dom);
      $body_dom = $html_dom->getElementsByTagName('article')
      ->item(0);
      $body = $body_dom->ownerDocument->saveXML($body_dom);*/

      // Meta tags.
      /** @var DOMElement $element */
@@ -248,18 +255,6 @@ class RemoteCollectionController extends ControllerBase {
      'filemime' => 'text/plain',
      ]);

      $file2 = File::create([
        'filename' => 'story.37464.min.js',
        'uri' => 'public://shorthand/stories/t2iQZSx4Km/static/story.37464.min.js',
        'filemime' => 'text/plain',
      ]);

      $file3 = File::create([
        'filename' => 'story.37464.min.css',
        'uri' => 'public://shorthand/stories/t2iQZSx4Km/static/story.37464.min.css',
        'filemime' => 'text/plain',
      ]);

      // Create story node.
      $node = Node::create([
      'type' => 'shorthand',
@@ -275,8 +270,6 @@ class RemoteCollectionController extends ControllerBase {
      $node->set('field_shstory_metatags', implode("\n", $metas + $scripts));
      $node->set('field_shstory_resources', [
      $file1,
        $file2,
        $file3,
      ]);

      $node->save();*/
@@ -288,6 +281,9 @@ class RemoteCollectionController extends ControllerBase {
    $context['results'] = $results;
  }

  /**
   * Callback to finish batch processing.
   */
  public static function downloadStoryComplete($success, $results, $operations) {
    // The 'success' parameter means no fatal PHP errors were detected. All
    // other error management should be handled using 'results'.
Loading