class LegalLanguageSettings in Legal 8
Same name and namespace in other branches
- 2.0.x src/Form/LegalLanguageSettings.php \Drupal\legal\Form\LegalLanguageSettings
Class LegalLanguageSettings.
@package Drupal\legal\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\legal\Form\LegalLanguageSettings
Expanded class hierarchy of LegalLanguageSettings
1 string reference to 'LegalLanguageSettings'
File
- src/
Form/ LegalLanguageSettings.php, line 18
Namespace
Drupal\legal\FormView source
class LegalLanguageSettings extends FormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* {@inheritdoc}
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'legal_language_settings';
}
/**
* Languages administration form.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$latest_header = [
$this
->t('Language'),
$this
->t('Version'),
$this
->t('Revision'),
];
$latest_rows = $this
->legalVersionsLatestGet();
$rows = [];
foreach ($latest_rows as $language_name => $language) {
$row = [];
$row[] = new HtmlEscapedText($language_name);
$row[] = empty($language['version']) ? '-' : $language['version'];
$row[] = empty($language['revision']) ? '-' : $language['revision'];
$rows[] = $row;
}
$form['latest'] = [
'#type' => 'details',
'#title' => $this
->t('Latest Version'),
];
$form['latest']['#value'] = [
'#type' => 'table',
'#header' => $latest_header,
'#rows' => $rows,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
/**
* Get latest version for each language.
*/
public function legalVersionsLatestGet($language = NULL) {
$conditions = [];
$current_version = $this->database
->select('legal_conditions', 'lc')
->fields('lc', [
'version',
])
->orderBy('version', 'DESC')
->range(0, 1)
->execute()
->fetchField();
// Get latest version for each language.
if (empty($language)) {
$languages = \Drupal::languageManager()
->getLanguages();
foreach ($languages as $language_id => $language) {
$result = $this->database
->select('legal_conditions', 'lc')
->fields('lc')
->condition('version', $current_version)
->condition('language', $language_id)
->orderBy('revision', 'DESC')
->range(0, 1)
->execute()
->fetchAllAssoc('tc_id');
$row = count($result) ? (object) array_shift($result) : FALSE;
$conditions[$language
->getId()] = $this
->legalVersionsLatestGetData($row);
}
}
else {
// Get latest version for specific language.
$result = $this->database
->select('legal_conditions', 'lc')
->fields('lc')
->condition('language', $language)
->groupBy('language')
->orderBy('version', 'DESC')
->range(0, 1)
->execute()
->fetchAllAssoc('tc_id');
$row = count($result) ? (object) array_shift($result) : FALSE;
$conditions[$language] = $this
->legalVersionsLatestGetData($row);
}
return $conditions;
}
/**
* Get data from T&C object.
*
* @param object $data
* T&C object.
*
* @return array
* T&C data as an array.
*/
public function legalVersionsLatestGetData($data) {
$row['revision'] = isset($data->revision) ? $data->revision : '';
$row['language'] = isset($data->language) ? $data->language : '';
$row['conditions'] = isset($data->conditions) ? $data->conditions : '';
$row['date'] = isset($data->date) ? $data->date : '';
$row['extras'] = isset($data->extras) ? $data->extras : '';
$row['changes'] = isset($data->changes) ? $data->changes : '';
return $row;
}
/**
* Access control callback.
*
* Check that Locale module is enabled and user has access permission.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
*/
public function access(AccountInterface $account) {
// Check permissions and combine with any custom access checking needed.
// Pass forward parameters from the route and/or request as needed.
if (!\Drupal::moduleHandler()
->moduleExists('locale')) {
return AccessResult::forbidden();
}
return AccessResult::allowed();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LegalLanguageSettings:: |
protected | property | The database connection. | |
LegalLanguageSettings:: |
public | function | Access control callback. | |
LegalLanguageSettings:: |
public | function |
Languages administration form. Overrides FormInterface:: |
|
LegalLanguageSettings:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LegalLanguageSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LegalLanguageSettings:: |
public | function | Get latest version for each language. | |
LegalLanguageSettings:: |
public | function | Get data from T&C object. | |
LegalLanguageSettings:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LegalLanguageSettings:: |
public | function | ||
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |