abstract class TextExtractorPluginBase in Search API attachments 9.0.x
Same name and namespace in other branches
- 8 src/TextExtractorPluginBase.php \Drupal\search_api_attachments\TextExtractorPluginBase
Base class for plugins able to extract file content.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\search_api_attachments\TextExtractorPluginBase implements ContainerFactoryPluginInterface, TextExtractorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TextExtractorPluginBase
6 files declare their use of TextExtractorPluginBase
- DocconvExtractor.php in src/
Plugin/ search_api_attachments/ DocconvExtractor.php - PdftotextExtractor.php in src/
Plugin/ search_api_attachments/ PdftotextExtractor.php - PythonPdf2txtExtractor.php in src/
Plugin/ search_api_attachments/ PythonPdf2txtExtractor.php - SolrExtractor.php in src/
Plugin/ search_api_attachments/ SolrExtractor.php - TikaExtractor.php in src/
Plugin/ search_api_attachments/ TikaExtractor.php
File
- src/
TextExtractorPluginBase.php, line 21
Namespace
Drupal\search_api_attachmentsView source
abstract class TextExtractorPluginBase extends PluginBase implements TextExtractorPluginInterface, ContainerFactoryPluginInterface {
/**
* Name of the config being edited.
*/
const CONFIGNAME = 'search_api_attachments.admin_config';
/**
* Config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Stream wrapper manager service.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* Mime type guesser service.
*
* @var \Symfony\Component\Mime\MimeTypeGuesserInterfacer
*/
protected $mimeTypeGuesser;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, MimeTypeGuesserInterface $mime_type_guesser, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->streamWrapperManager = $stream_wrapper_manager;
$this->mimeTypeGuesser = $mime_type_guesser;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('stream_wrapper_manager'), $container
->get('file.mime_type.guesser'), $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function extract(File $file) {
$filename = $file;
$mode = 'r';
return fopen($filename, $mode);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function getmessenger() {
return $this->messenger;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration += $configuration;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$extractor_plugin_id = $form_state
->getValue('extraction_method');
$config = $this->configFactory
->getEditable(static::CONFIGNAME);
$config
->set($extractor_plugin_id . '_configuration', $this->configuration);
$config
->save();
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* Helper method to get the real path from an uri.
*
* @param string $uri
* The URI of the file, e.g. public://directory/file.jpg.
*
* @return mixed
* The real path to the file if it is a local file. An URL otherwise.
*/
public function getRealpath($uri) {
$wrapper = $this->streamWrapperManager
->getViaUri($uri);
$scheme = $this->streamWrapperManager
->getScheme($uri);
$local_wrappers = $this->streamWrapperManager
->getWrappers(StreamWrapperInterface::LOCAL);
if (in_array($scheme, array_keys($local_wrappers))) {
return $wrapper
->realpath();
}
else {
return $wrapper
->getExternalUrl();
}
}
/**
* Helper method to get the PDF MIME types.
*
* @return array
* An array of the PDF MIME types.
*/
public function getPdfMimeTypes() {
$pdf_mime_types = [];
$pdf_mime_types[] = $this->mimeTypeGuesser
->guessMimeType('dummy.pdf');
return $pdf_mime_types;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginFormInterface:: |
public | function | Form constructor. | 37 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TextExtractorPluginBase:: |
protected | property | Config factory service. | |
TextExtractorPluginBase:: |
protected | property |
The messenger. Overrides MessengerTrait:: |
|
TextExtractorPluginBase:: |
protected | property | Mime type guesser service. | |
TextExtractorPluginBase:: |
protected | property | Stream wrapper manager service. | |
TextExtractorPluginBase:: |
public | function | ||
TextExtractorPluginBase:: |
constant | Name of the config being edited. | ||
TextExtractorPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
TextExtractorPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
TextExtractorPluginBase:: |
public | function |
Extract method. Overrides TextExtractorPluginInterface:: |
6 |
TextExtractorPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
TextExtractorPluginBase:: |
public | function | ||
TextExtractorPluginBase:: |
public | function | Helper method to get the PDF MIME types. | |
TextExtractorPluginBase:: |
public | function | Helper method to get the real path from an uri. | |
TextExtractorPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
TextExtractorPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
6 |
TextExtractorPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
5 |
TextExtractorPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
2 |