You are here

editor_note.module in Editor Notes 8

Same filename and directory in other branches
  1. 7 editor_note.module

Contains editor_node.module.

File

editor_note.module
View source
<?php

/**
 * @file
 * Contains editor_node.module.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\editor_note\Hook\EntityHook;
use Drupal\user\UserInterface;
use Drupal\field\Entity\FieldConfig;

/**
 * Implements hook_entity_delete().
 */
function editor_note_entity_delete(EntityInterface $entity) {
  \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityHook::class)
    ->onEntityDelete($entity);
}

/**
 * Implements hook_entity_revision_delete().
 */
function editor_note_entity_revision_delete(EntityInterface $entity) {
  \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityHook::class)
    ->onEntityRevisionDelete($entity);
}

/**
 * Implements hook_entity_insert().
 */
function editor_note_entity_insert(EntityInterface $entity) {
  \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityHook::class)
    ->onEntityInsert($entity);
}

/**
 * Implements hook_entity_update().
 */
function editor_note_entity_update(EntityInterface $entity) {
  \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityHook::class)
    ->onEntityInsert($entity);
}

/**
 * Implements hook_ENTITY_TYPE_delete().
 */
function editor_note_user_delete(EntityInterface $entity) {
  \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityHook::class)
    ->onUserDelete($entity);
}

/**
 * Implements hook_user_cancel().
 */
function editor_note_user_cancel($edit, UserInterface $account, $method) {
  switch ($method) {
    case 'user_cancel_reassign':
      \Drupal::service('class_resolver')
        ->getInstanceFromDefinition(EntityHook::class)
        ->onUserCancel($account);
      break;
    default:
      break;
  }
}

/**
 * Implements hook_field_purge_field().
 */
function editor_note_field_purge_field(FieldConfig $field) {
  if ($field
    ->getType() == 'editor_note_item') {
    \Drupal::service('class_resolver')
      ->getInstanceFromDefinition(EntityHook::class)
      ->onFieldDelete($field);
  }
}

/**
 * Implements hook_help().
 */
function editor_note_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.editor_note') {
    $renderer = \Drupal::service('renderer');
    $output = '<h3>' . t('About') . '</h3>';
    $output .= '<p>' . t('The modules improves administration/editorial usability and provides configurable "Editor Notes" field, which can be added to any Drupal entity.') . '</p>';
    $output .= '<p>' . t('Concept of "Editor Notes" is similar to "Comments". The main difference is that "Editor Notes" are for editors and admins rather than for end users.') . '</p>';
    $output .= '<h3>' . t('Usage') . '</h3>';
    $usage = [
      t('As website editor I can write status notes to myself and other editors working on the same material.'),
      t('The module provides "Editor Notes" field available on "Manage Fields" page.'),
      t('This field can also be added to any Drupal fieldable entity (user etc).'),
      t('List of previously added notes displays in "content edit" form in configurable table.'),
      t('Notes can also be displayed for the end user in configurable table if necessary.'),
      t('When editor opens "content add" form for the first time he sees a field (textarea) providing him an option to add the first note.'),
      t('When editor opens "content edit" form he sees "Editor Notes" widget with already added notes if any found.'),
    ];
    $usage_list = [
      '#theme' => 'item_list',
      '#items' => $usage,
    ];
    $output .= $renderer
      ->render($usage_list);
    $output .= '<h3>' . t('Features') . '</h3>';
    $features = [
      t('Website editor can only add / update / delete his own notes by default.'),
      t('However notes may also be updated or removed by any user with "Administer any editor note" permission.'),
      t('CRUD operations on notes support Ajax and perform in configurable modal window without page reload.'),
      t('Module supports Views, content revisions and content translation.'),
    ];
    $features_list = [
      '#theme' => 'item_list',
      '#items' => $features,
    ];
    $output .= $renderer
      ->render($features_list);
    $output .= '<h3>' . t('Similar Projects') . '</h3>';
    $output .= '<p><strong>' . t('The key feature of the Editor Notes module is that editor is able to browse (add/update/remove) notes directly in "edit content" form.') . '</strong></p>';
    $output .= '<p>' . t('It helps to save time when adding/updating large amount of content.') . '</p>';
    $projects = [
      t('@module creates a block that displays a textarea pre-filled with the existing comment for that specific page.', [
        '@module' => $renderer
          ->render(Link::fromTextAndUrl(t('Admin Notes'), Url::fromUri('https://www.drupal.org/project/admin_notes'))
          ->toRenderable()),
      ]),
      t('@module introduces a new content type "sitenotes." It also creates a menu item in the Admin >> Site building menu, where it is available only to privileged users.', [
        '@module' => $renderer
          ->render(Link::fromTextAndUrl(t('SiteNotes'), Url::fromUri('https://www.drupal.org/project/sitenotes'))
          ->toRenderable()),
      ]),
      t('@module consist of titles and text rendered into a block. The notes are specific to each authenticated user and can only be viewed by the user who created them.', [
        '@module' => $renderer
          ->render(Link::fromTextAndUrl(t('Personal Notes'), Url::fromUri('https://www.drupal.org/project/personal_notes'))
          ->toRenderable()),
      ]),
      t('@module creates a block with the ability to add, delete and edit notes. Notes are stored on a per path basis and the block can be made visible to certain roles/paths.', [
        '@module' => $renderer
          ->render(Link::fromTextAndUrl(t('Stickynote'), Url::fromUri('https://www.drupal.org/project/stickynote'))
          ->toRenderable()),
      ]),
    ];
    $project_list = [
      '#theme' => 'item_list',
      '#items' => $projects,
    ];
    $output .= $renderer
      ->render($project_list);
    $output .= '<p>' . t('The difference from mentioned above modules is that Editor Notes creates configurable ajaxified field (instead of blocks or content type).') . '</p>';
    $output .= '<p>' . t('Field can be attached to an entity and associated with that entity. Each field item controls CRUD operations based on authorship (like Comment module).') . '</p>';
    $output .= '<h3>' . t('Installation') . '</h3>';
    $installation = [
      t('Drop the entire Editor Note module into your "modules" folder.'),
      t('Enable the module from the @page.', [
        '@page' => $renderer
          ->render(Link::fromTextAndUrl(t('modules page'), Url::fromRoute('system.modules_list'))
          ->toRenderable()),
      ]),
      t('Create new or edit existing content type and add a new field of type "Editor Notes".'),
    ];
    $installation_list = [
      '#theme' => 'item_list',
      '#items' => $installation,
      '#list_type' => 'ol',
    ];
    $output .= $renderer
      ->render($installation_list);
    $output .= '<h3>' . t('Sponsorship') . '</h3>';
    $credit = [
      $renderer
        ->render(Link::fromTextAndUrl(t('EPAM Systems'), Url::fromUri('https://www.drupal.org/node/2114867'))
        ->toRenderable()),
      $renderer
        ->render(Link::fromTextAndUrl(t('NBC Universal'), Url::fromUri('http://www.nbcuni.com'))
        ->toRenderable()),
    ];
    $output .= '<p>' . t('This project was sponsored by:') . '</p>';
    $credit_list = [
      '#theme' => 'item_list',
      '#items' => $credit,
    ];
    $output .= $renderer
      ->render($credit_list);
    $output .= '<h3>' . t('Acknowledgments') . '</h3>';
    $output .= '<p>' . t('Special thanks to @username1 and @username2 for reviewing the module.', [
      '@username1' => $renderer
        ->render(Link::fromTextAndUrl(t('Sergei Churilo'), Url::fromUri('https://www.drupal.org/user/584658'))
        ->toRenderable()),
      '@username2' => $renderer
        ->render(Link::fromTextAndUrl(t('Alexey Yahnenko'), Url::fromUri('https://www.drupal.org/user/2635711'))
        ->toRenderable()),
    ]) . '</p>';
    $output .= '<h3>' . t('Author') . '</h3>';
    $output .= '<p>' . $renderer
      ->render(Link::fromTextAndUrl(t('Rostislav Sergeenkov'), Url::fromUri('https://www.drupal.org/u/rostislav-sergeenkov'))
      ->toRenderable()) . '</p>';
    return $output;
  }
}