abstract class UserExportPluginBase in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 8.3 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 8.5 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 8.6 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 8.7 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 8.8 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 10.3.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 10.0.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 10.1.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
- 10.2.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase
Base class for User export plugin plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\social_user_export\Plugin\UserExportPluginBase implements ContainerFactoryPluginInterface, UserExportPluginInterface uses StringTranslationTrait
Expanded class hierarchy of UserExportPluginBase
37 files declare their use of UserExportPluginBase
- OrganizationTag.php in modules/
social_features/ social_profile/ modules/ social_profile_organization_tag/ src/ Plugin/ UserExportPlugin/ OrganizationTag.php - UserAccountName.php in modules/
social_features/ social_user_export/ src/ Plugin/ UserExportPlugin/ UserAccountName.php - UserAddressAdministrative.php in modules/
social_features/ social_user_export/ src/ Plugin/ UserExportPlugin/ UserAddressAdministrative.php - UserAddressCountryCode.php in modules/
social_features/ social_user_export/ src/ Plugin/ UserExportPlugin/ UserAddressCountryCode.php - UserAddressLine1.php in modules/
social_features/ social_user_export/ src/ Plugin/ UserExportPlugin/ UserAddressLine1.php
File
- modules/
social_features/ social_user_export/ src/ Plugin/ UserExportPluginBase.php, line 19
Namespace
Drupal\social_user_export\PluginView source
abstract class UserExportPluginBase extends PluginBase implements UserExportPluginInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
public $entityTypeManager;
/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
public $dateFormatter;
/**
* The database.
*
* @var \Drupal\Core\Database\Connection
*/
public $database;
/**
* UserExportPluginBase constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DateFormatterInterface $date_formatter, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->dateFormatter = $date_formatter;
$this->database = $database;
}
/**
* The create method.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* Container interface.
* @param array $configuration
* An array of configuration.
* @param string $plugin_id
* The plugin id.
* @param mixed $plugin_definition
* The plugin definition.
*
* @return \Drupal\Core\Plugin\ContainerFactoryPluginInterface|\Drupal\social_user_export\Plugin\UserExportPluginBase
* Returns the UserExportPluginBase.
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('date.formatter'), $container
->get('database'));
}
/**
* Returns the header.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup|string
* The header.
*/
public function getHeader() {
return '';
}
/**
* Returns the value.
*
* @param \Drupal\user\UserInterface $entity
* The User entity to get the value from.
*
* @return string
* The value.
*/
public function getValue(UserInterface $entity) {
return '';
}
/**
* Get the Profile entity.
*
* @param \Drupal\user\UserInterface $entity
* The user entity to get the profile from.
*
* @return \Drupal\profile\Entity\ProfileInterface|null
* Returns the Profile or NULL if profile does not exist.
*/
public function getProfile(UserInterface $entity) {
$user_profile = NULL;
/** @var \Drupal\profile\ProfileStorageInterface $storage */
try {
$storage = $this->entityTypeManager
->getStorage('profile');
if (!empty($storage)) {
$user_profile = $storage
->loadByUser($entity, 'profile', TRUE);
// TODO: Remove once #3005113 is fixed in the profile module.
if ($user_profile === FALSE) {
$user_profile = NULL;
}
}
} catch (\Exception $e) {
}
return $user_profile;
}
/**
* Returns the value of a field for a given profile.
*
* @param string $field_name
* The field name to get the value for.
* @param \Drupal\profile\Entity\ProfileInterface $user_profile
* The profile to get the data for.
*
* @return string
* Returns value of the field.
*/
public function profileGetFieldValue($field_name, ProfileInterface $user_profile = NULL) {
if ($user_profile === NULL) {
return '';
}
try {
$value = $user_profile
->get($field_name)->value;
} catch (\Exception $e) {
$value = '';
}
return $value;
}
/**
* Returns the value for the address field and element within address.
*
* @param string $field_name
* The field name to get the value for.
* @param string $address_element
* The address element to get the value for, e.g. 'country_code'.
* @param \Drupal\profile\Entity\ProfileInterface $user_profile
* The profile to get the data for.
*
* @return string
* Returns the value of the address element for the profile.
*/
public function profileGetAddressFieldValue($field_name, $address_element, ProfileInterface $user_profile = NULL) {
if ($user_profile === NULL) {
return '';
}
$value = '';
try {
$address = $user_profile
->get($field_name)
->getValue();
if (isset($address['0'][$address_element])) {
$value = $address['0'][$address_element];
}
} catch (\Exception $e) {
$value = '';
}
return $value;
}
/**
* Returns the values of a taxonomy reference field.
*
* @param string $field_name
* The field name to get the value for, should be taxonomy term reference.
* @param \Drupal\profile\Entity\ProfileInterface $user_profile
* The profile to get the data for.
*
* @return string
* Returns comma separated string of taxonomy terms of the field.
*/
public function profileGetTaxonomyFieldValue($field_name, ProfileInterface $user_profile = NULL) {
if ($user_profile === NULL) {
return '';
}
$concatenated_value = '';
try {
$values = $user_profile
->get($field_name)
->getValue();
if (is_array($values) && !empty($values)) {
$taxonomy_terms = [];
foreach ($values as $x => $value) {
if (isset($value['target_id'])) {
/** @var \Drupal\taxonomy\Entity\Term $term */
$taxonomy_term = Term::load($value['target_id']);
$taxonomy_terms[] = $taxonomy_term
->getName();
}
}
$concatenated_value = implode(', ', $taxonomy_terms);
}
} catch (\Exception $e) {
$concatenated_value = '';
}
return $concatenated_value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | |
UserExportPluginBase:: |
public | property | The database. | |
UserExportPluginBase:: |
public | property | The date formatter. | |
UserExportPluginBase:: |
public | property | The entity type manager. | |
UserExportPluginBase:: |
public static | function |
The create method. Overrides ContainerFactoryPluginInterface:: |
2 |
UserExportPluginBase:: |
public | function |
Returns the header. Overrides UserExportPluginInterface:: |
37 |
UserExportPluginBase:: |
public | function |
Get the Profile entity. Overrides UserExportPluginInterface:: |
|
UserExportPluginBase:: |
public | function |
Returns the value. Overrides UserExportPluginInterface:: |
37 |
UserExportPluginBase:: |
public | function |
Returns the value for the address field and element within address. Overrides UserExportPluginInterface:: |
|
UserExportPluginBase:: |
public | function |
Returns the value of a field for a given profile. Overrides UserExportPluginInterface:: |
|
UserExportPluginBase:: |
public | function |
Returns the values of a taxonomy reference field. Overrides UserExportPluginInterface:: |
|
UserExportPluginBase:: |
public | function |
UserExportPluginBase constructor. Overrides PluginBase:: |
2 |