96 lines
5.5 KiB
Plaintext
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>
|
|
<div class="pub__container">
|
|
<div class="pub__cover">
|
|
<img src="{{field_image}}" class="pub__image">
|
|
</div>
|
|
<h5>{{title}}</h5>
|
|
<h6>{{created}}</h6>
|
|
<div class="pub__middle">
|
|
<div class="pub__text">
|
|
<a class="btn btn-default" href="#" role="button" data-action="freepaper-info" data-id="pub_i{{nid}}" data-title=" {{ title }}" data-body="{{ body }}" ><i class="fa fa-1x fa-info-circle"></i> Info</a>
|
|
<a class="btn" href="#" role="button" data-action="freepaper-flipbook" data-id="pub_f{{nid}}" data-title=" {{ title_1 }}" data-pdf="{{ field_pdf }}"><i class="fa fa-1x fa-book-open"></i> View</a>
|
|
<a class="btn" href="{{ field_pdf }}" target="_blank"><i class="fa fa-1x fa-download"></i> Download</a>
|
|
</div>
|
|
</div>
|
|
<div class="receiver"></div>
|
|
</div>
|
|
</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;
|
|
}
|