freepaper/freepaper.module
2023-12-14 11:32:04 -06:00

96 lines
5.5 KiB
Plaintext

<?php
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\freepaper\Entity\Flipbook;
use Drupal\Core\Url;
/** ADDED FOR D10 */
use Drupal\Core\Extension\ExtensionPathResolver;
/**
* Implements hook_help().
*/
function freepaper_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.freepaper':
return t('
<h2>Freepaper Info and Flipbook</h2>
<h3>Description</h3>
<p>This is a custom module which works with the Above All template for the twelvetribes.org website.
The module displays two different modals (popups): Info and Flipbook. Info displays the body text of the
Publication, along with its image and title. The Flipbook displays a browsable 3D view of the PDF.
<h3>Requirements</h3>
The 3dflipbook plugin is found at: <a href="https://3dflipbook.net">https://3dflipbook.net</a>. We have a license.</p>
<h3>Configuration</h3>
The module works best by creating a view of Publications. Add fields to the views, and exclude them (make them hidden).
Then, create a visible "Global: Custom Text" and put this in the text:
<pre><code>
&#060;div class=&#034;pub__container&#034;&#062;
&#060;div class=&#034;pub__cover&#034;&#062;
&#060;img src=&#034;{{field_image}}&#034; class=&#034;pub__image&#034;&#062;
&#060;/div&#062;
&#060;h5&#062;{{title}}&#060;/h5&#062;
&#060;h6&#062;{{created}}&#060;/h6&#062;
&#060;div class=&#034;pub__middle&#034;&#062;
&#060;div class=&#034;pub__text&#034;&#062;
&#060;a class=&#034;btn btn-default&#034; href=&#034;#&#034; role=&#034;button&#034; data-action=&#034;freepaper-info&#034; data-id=&#034;pub_i{{nid}}&#034; data-title=&#034; {{ title }}&#034; data-body=&#034;{{ body }}&#034; &#062;&#060;i class=&#034;fa fa-1x fa-info-circle&#034;&#062;&#060;/i&#062; Info&#060;/a&#062;
&#060;a class=&#034;btn&#034; href=&#034;#&#034; role=&#034;button&#034; data-action=&#034;freepaper-flipbook&#034; data-id=&#034;pub_f{{nid}}&#034; data-title=&#034; {{ title_1 }}&#034; data-pdf=&#034;{{ field_pdf }}&#034;&#062;&#060;i class=&#034;fa fa-1x fa-book-open&#034;&#062;&#060;/i&#062; View&#060;/a&#062;
&#060;a class=&#034;btn&#034; href=&#034;{{ field_pdf }}&#034; target=&#034;_blank&#034;&#062;&#060;i class=&#034;fa fa-1x fa-download&#034;&#062;&#060;/i&#062; Download&#060;/a&#062;
&#060;/div&#062;
&#060;/div&#062;
&#060;div class=&#034;receiver&#034;&#062;&#060;/div&#062;
&#060;/div&#062;
</code></pre>
The classes and structure are important. They work together with the other files to load new text into the <b>receiver</b> element.
<h4>Fields</h4>
<ul>
<li><b>field_image</b> is a thumbnail of the Publication.</li>
<li><b>title</b> is the title of the publication.</li>
<li><b>created</b> is the date of publication.</li>
<li><b>body</b> is the body of the publication containing text about the publication.</li>
<li><b>field_pdf</b> is a FileField that contains the URL to File of the publication.</li>
</ul>
<h4>Data Attributes</h4>
Within the <b>Button</b> tags are several data attributes, which are used to pass data to the javascript functions.
<ul>
<li><b>data-action</b>
<ol>
<li><b>freepaper-info</b> : Tells this button to open the Info modal.</li>
<li><b>freepaper-flipbook</b> : Tells this button to open the Flipbook modal.</li>
</ol>
</li>
<li><b>data-body</b> : For Info modals, this contains the body of the Publication node to display.</li>
<li><b>data-pdf</b> : For Flipbook modals, this contains the filename of the PDF.</li>
</ul>
<h4>Receiver</h4>
Within each <b>div.pub__container</b>, outside of all other elements but within the DIV, you must have a <b>div.receiver</b>. The module trader_will
fill that DIV tag with new content to create the modal.
<pre><code><div class="receiver"></div></code></pre>
<h3>Files</h3>
<ul>
<li><b>info-modal.html</b> : template for the info modal that gets loaded into the receiver.</li>
<li><b>flipbook-modal.html</b> : template for the flipbook modal that gets loaded into the receiver.</li>
<li><b>modules/custom/freepaper/js/freepaper-actions.js</b> : scripts to load the receiver</li>
<li><b>modules/custom/freepaper</b> : the location of the modules, its dependencies, and the module.</li>
</ul>
<p>- Mevaser</p>
');
}
}
function freepaper_preprocess_page(&$variables){
// Drupal 8-9
// global $base_url;
// $host = $base_url;
// $variables['#attached']['drupalSettings']['modulepath'] = drupal_get_path('module', 'freepaper');
// $variables['#attached']['drupalSettings']['host'] = $host;
// // $variables['#attached']['library'][] = 'freepaper/flipbook'; We will attach it in the twig template
// DRUPAL 10
$host = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$extension_path_resolver = Drupal::service('extension.path.resolver');
$module_path = $extension_path_resolver->getPath('module', 'freepaper');
$variables['#attached']['drupalSettings']['modulepath'] = $module_path;
$variables['#attached']['drupalSettings']['host'] = $host;
}