EpubFormatterBase.php in Epub 8
File
src/Plugin/Field/FieldFormatter/EpubFormatterBase.php
View source
<?php
namespace Drupal\epub\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
class EpubFormatterBase extends FileFormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $file) {
$elements[$delta] = array(
'#theme' => 'epub_formatter_default',
'#file' => $file,
'#width' => $this
->getSetting('width'),
'#height' => $this
->getSetting('height'),
);
}
return $elements;
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['epub_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $this
->getSetting('width'),
'#description' => t('The width of ebook viewer area.'),
);
$element['epub_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $this
->getSetting('height'),
'#description' => t('The height of ebook viewer area. If "auto" is used, the iframe will auto-fit the epub document height and anchors in links will not work correctly.'),
);
return $element;
}
public static function defaultSettings() {
$settings['width'] = '100%';
$settings['height'] = 'auto';
return $settings;
}
}