Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
|
@ -34,12 +34,12 @@ class FileExtensionFormatter extends BaseFieldFileFormatterBase {
|
|||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::settingsForm($form, $form_state);
|
||||
$form['extension_detect_tar'] = array(
|
||||
$form['extension_detect_tar'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Include tar in extension'),
|
||||
'#description' => $this->t("If the part of the filename just before the extension is '.tar', include this in the extension output."),
|
||||
'#default_value' => $this->getSetting('extension_detect_tar'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ class FilemimeFormatter extends BaseFieldFileFormatterBase {
|
|||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::settingsForm($form, $form_state);
|
||||
|
||||
$form['filemime_image'] = array(
|
||||
$form['filemime_image'] = [
|
||||
'#title' => $this->t('Display an icon'),
|
||||
'#description' => $this->t('The icon is representing the file type, instead of the MIME text (such as "image/jpeg")'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->getSetting('filemime_image'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,21 +21,21 @@ class GenericFileFormatter extends FileFormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||
$item = $file->_referringItem;
|
||||
$elements[$delta] = array(
|
||||
$elements[$delta] = [
|
||||
'#theme' => 'file_link',
|
||||
'#file' => $file,
|
||||
'#description' => $item->description,
|
||||
'#cache' => array(
|
||||
'#cache' => [
|
||||
'tags' => $file->getCacheTags(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Pass field item attributes to the theme function.
|
||||
if (isset($item->_attributes)) {
|
||||
$elements[$delta] += array('#attributes' => array());
|
||||
$elements[$delta] += ['#attributes' => []];
|
||||
$elements[$delta]['#attributes'] += $item->_attributes;
|
||||
// Unset field item attributes since they have been included in the
|
||||
// formatter output and should not be rendered in the field template.
|
||||
|
|
|
|||
|
|
@ -25,17 +25,17 @@ class RSSEnclosureFormatter extends FileFormatterBase {
|
|||
// Add the first file as an enclosure to the RSS item. RSS allows only one
|
||||
// enclosure per item. See: http://wikipedia.org/wiki/RSS_enclosure
|
||||
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||
$entity->rss_elements[] = array(
|
||||
$entity->rss_elements[] = [
|
||||
'key' => 'enclosure',
|
||||
'attributes' => array(
|
||||
'attributes' => [
|
||||
// In RSS feeds, it is necessary to use absolute URLs. The 'url.site'
|
||||
// cache context is already associated with RSS feed responses, so it
|
||||
// does not need to be specified here.
|
||||
'url' => file_create_url($file->getFileUri()),
|
||||
'length' => $file->getSize(),
|
||||
'type' => $file->getMimeType(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,33 +21,33 @@ class TableFormatter extends FileFormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
if ($files = $this->getEntitiesToView($items, $langcode)) {
|
||||
$header = array(t('Attachment'), t('Size'));
|
||||
$rows = array();
|
||||
$header = [t('Attachment'), t('Size')];
|
||||
$rows = [];
|
||||
foreach ($files as $delta => $file) {
|
||||
$rows[] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows[] = [
|
||||
[
|
||||
'data' => [
|
||||
'#theme' => 'file_link',
|
||||
'#file' => $file,
|
||||
'#cache' => array(
|
||||
'#cache' => [
|
||||
'tags' => $file->getCacheTags(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array('data' => format_size($file->getSize())),
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
['data' => format_size($file->getSize())],
|
||||
];
|
||||
}
|
||||
|
||||
$elements[0] = array();
|
||||
$elements[0] = [];
|
||||
if (!empty($rows)) {
|
||||
$elements[0] = array(
|
||||
$elements[0] = [
|
||||
'#theme' => 'table__file_formatter_table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ class UrlPlainFormatter extends FileFormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||
$elements[$delta] = array(
|
||||
$elements[$delta] = [
|
||||
'#markup' => file_url_transform_relative(file_create_url($file->getFileUri())),
|
||||
'#cache' => array(
|
||||
'#cache' => [
|
||||
'tags' => $file->getCacheTags(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $elements;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class FileFieldItemList extends EntityReferenceFieldItemList {
|
|||
else {
|
||||
// Get current target file entities and file IDs.
|
||||
$files = $this->referencedEntities();
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
|
||||
/** @var \Drupal\file\FileInterface $file */
|
||||
foreach ($files as $file) {
|
||||
|
|
@ -48,7 +48,7 @@ class FileFieldItemList extends EntityReferenceFieldItemList {
|
|||
|
||||
// Get the file IDs attached to the field before this update.
|
||||
$field_name = $this->getFieldDefinition()->getName();
|
||||
$original_ids = array();
|
||||
$original_ids = [];
|
||||
$langcode = $this->getLangcode();
|
||||
$original = $entity->original;
|
||||
if ($original->hasTranslation($langcode)) {
|
||||
|
|
|
|||
|
|
@ -32,59 +32,59 @@ class FileItem extends EntityReferenceItem {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultStorageSettings() {
|
||||
return array(
|
||||
return [
|
||||
'target_type' => 'file',
|
||||
'display_field' => FALSE,
|
||||
'display_default' => FALSE,
|
||||
'uri_scheme' => file_default_scheme(),
|
||||
) + parent::defaultStorageSettings();
|
||||
] + parent::defaultStorageSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultFieldSettings() {
|
||||
return array(
|
||||
return [
|
||||
'file_extensions' => 'txt',
|
||||
'file_directory' => '[date:custom:Y]-[date:custom:m]',
|
||||
'max_filesize' => '',
|
||||
'description_field' => 0,
|
||||
) + parent::defaultFieldSettings();
|
||||
] + parent::defaultFieldSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'target_id' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'target_id' => [
|
||||
'description' => 'The ID of the file entity.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'display' => array(
|
||||
],
|
||||
'display' => [
|
||||
'description' => 'Flag to control whether this file should be displayed when viewing content.',
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'default' => 1,
|
||||
),
|
||||
'description' => array(
|
||||
],
|
||||
'description' => [
|
||||
'description' => 'A description of the file.',
|
||||
'type' => 'text',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'target_id' => array('target_id'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'target_id' => array(
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'target_id' => ['target_id'],
|
||||
],
|
||||
'foreign keys' => [
|
||||
'target_id' => [
|
||||
'table' => 'file_managed',
|
||||
'columns' => array('target_id' => 'fid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
'columns' => ['target_id' => 'fid'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,37 +107,37 @@ class FileItem extends EntityReferenceItem {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
|
||||
$element = array();
|
||||
$element = [];
|
||||
|
||||
$element['#attached']['library'][] = 'file/drupal.file';
|
||||
|
||||
$element['display_field'] = array(
|
||||
$element['display_field'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable <em>Display</em> field'),
|
||||
'#default_value' => $this->getSetting('display_field'),
|
||||
'#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'),
|
||||
);
|
||||
$element['display_default'] = array(
|
||||
];
|
||||
$element['display_default'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Files displayed by default'),
|
||||
'#default_value' => $this->getSetting('display_default'),
|
||||
'#description' => t('This setting only has an effect if the display option is enabled.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="settings[display_field]"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="settings[display_field]"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE);
|
||||
$element['uri_scheme'] = array(
|
||||
$element['uri_scheme'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Upload destination'),
|
||||
'#options' => $scheme_options,
|
||||
'#default_value' => $this->getSetting('uri_scheme'),
|
||||
'#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),
|
||||
'#disabled' => $has_data,
|
||||
);
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
|
@ -146,50 +146,50 @@ class FileItem extends EntityReferenceItem {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
|
||||
$element = array();
|
||||
$element = [];
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$element['file_directory'] = array(
|
||||
$element['file_directory'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('File directory'),
|
||||
'#default_value' => $settings['file_directory'],
|
||||
'#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
|
||||
'#element_validate' => array(array(get_class($this), 'validateDirectory')),
|
||||
'#element_validate' => [[get_class($this), 'validateDirectory']],
|
||||
'#weight' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
// Make the extension list a little more human-friendly by comma-separation.
|
||||
$extensions = str_replace(' ', ', ', $settings['file_extensions']);
|
||||
$element['file_extensions'] = array(
|
||||
$element['file_extensions'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Allowed file extensions'),
|
||||
'#default_value' => $extensions,
|
||||
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
|
||||
'#element_validate' => array(array(get_class($this), 'validateExtensions')),
|
||||
'#element_validate' => [[get_class($this), 'validateExtensions']],
|
||||
'#weight' => 1,
|
||||
'#maxlength' => 256,
|
||||
// By making this field required, we prevent a potential security issue
|
||||
// that would allow files of any type to be uploaded.
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$element['max_filesize'] = array(
|
||||
$element['max_filesize'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Maximum upload size'),
|
||||
'#default_value' => $settings['max_filesize'],
|
||||
'#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))),
|
||||
'#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', ['%limit' => format_size(file_upload_max_size())]),
|
||||
'#size' => 10,
|
||||
'#element_validate' => array(array(get_class($this), 'validateMaxFilesize')),
|
||||
'#element_validate' => [[get_class($this), 'validateMaxFilesize']],
|
||||
'#weight' => 5,
|
||||
);
|
||||
];
|
||||
|
||||
$element['description_field'] = array(
|
||||
$element['description_field'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable <em>Description</em> field'),
|
||||
'#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '',
|
||||
'#description' => t('The description field allows users to enter a description about the uploaded file.'),
|
||||
'#weight' => 11,
|
||||
);
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
|
@ -245,7 +245,7 @@ class FileItem extends EntityReferenceItem {
|
|||
*/
|
||||
public static function validateMaxFilesize($element, FormStateInterface $form_state) {
|
||||
if (!empty($element['#value']) && !is_numeric(Bytes::toInt($element['#value']))) {
|
||||
$form_state->setError($element, t('The "@name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('@name' => $element['title'])));
|
||||
$form_state->setError($element, t('The "@name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', ['@name' => $element['title']]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -253,15 +253,15 @@ class FileItem extends EntityReferenceItem {
|
|||
* Determines the URI for a file field.
|
||||
*
|
||||
* @param array $data
|
||||
* An array of token objects to pass to token_replace().
|
||||
* An array of token objects to pass to Token::replace().
|
||||
*
|
||||
* @return string
|
||||
* An unsanitized file directory URI with tokens replaced. The result of
|
||||
* the token replacement is then converted to plain text and returned.
|
||||
*
|
||||
* @see token_replace()
|
||||
* @see \Drupal\Core\Utility\Token::replace()
|
||||
*/
|
||||
public function getUploadLocation($data = array()) {
|
||||
public function getUploadLocation($data = []) {
|
||||
return static::doGetUploadLocation($this->getSettings(), $data);
|
||||
}
|
||||
|
||||
|
|
@ -271,11 +271,13 @@ class FileItem extends EntityReferenceItem {
|
|||
* @param array $settings
|
||||
* The array of field settings.
|
||||
* @param array $data
|
||||
* An array of token objects to pass to token_replace().
|
||||
* An array of token objects to pass to Token::replace().
|
||||
*
|
||||
* @return string
|
||||
* An unsanitized file directory URI with tokens replaced. The result of
|
||||
* the token replacement is then converted to plain text and returned.
|
||||
*
|
||||
* @see \Drupal\Core\Utility\Token::replace()
|
||||
*/
|
||||
protected static function doGetUploadLocation(array $settings, $data = []) {
|
||||
$destination = trim($settings['file_directory'], '/');
|
||||
|
|
@ -294,7 +296,7 @@ class FileItem extends EntityReferenceItem {
|
|||
* element's '#upload_validators' property.
|
||||
*/
|
||||
public function getUploadValidators() {
|
||||
$validators = array();
|
||||
$validators = [];
|
||||
$settings = $this->getSettings();
|
||||
|
||||
// Cap the upload size according to the PHP limit.
|
||||
|
|
@ -304,11 +306,11 @@ class FileItem extends EntityReferenceItem {
|
|||
}
|
||||
|
||||
// There is always a file size limit due to the PHP server limit.
|
||||
$validators['file_validate_size'] = array($max_filesize);
|
||||
$validators['file_validate_size'] = [$max_filesize];
|
||||
|
||||
// Add the extension check if necessary.
|
||||
if (!empty($settings['file_extensions'])) {
|
||||
$validators['file_validate_extensions'] = array($settings['file_extensions']);
|
||||
$validators['file_validate_extensions'] = [$settings['file_extensions']];
|
||||
}
|
||||
|
||||
return $validators;
|
||||
|
|
@ -329,11 +331,11 @@ class FileItem extends EntityReferenceItem {
|
|||
$destination = $dirname . '/' . $random->name(10, TRUE) . '.txt';
|
||||
$data = $random->paragraphs(3);
|
||||
$file = file_save_data($data, $destination, FILE_EXISTS_ERROR);
|
||||
$values = array(
|
||||
$values = [
|
||||
'target_id' => $file->id(),
|
||||
'display' => (int)$settings['display_default'],
|
||||
'description' => $random->sentences(10),
|
||||
);
|
||||
];
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,27 +48,27 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings() {
|
||||
return array(
|
||||
return [
|
||||
'progress_indicator' => 'throbber',
|
||||
) + parent::defaultSettings();
|
||||
] + parent::defaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$element['progress_indicator'] = array(
|
||||
$element['progress_indicator'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Progress indicator'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'throbber' => t('Throbber'),
|
||||
'bar' => t('Bar with progress meter'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $this->getSetting('progress_indicator'),
|
||||
'#description' => t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'),
|
||||
'#weight' => 16,
|
||||
'#access' => file_progress_implementation(),
|
||||
);
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
|
@ -76,8 +76,8 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary() {
|
||||
$summary = array();
|
||||
$summary[] = t('Progress indicator: @progress_indicator', array('@progress_indicator' => $this->getSetting('progress_indicator')));
|
||||
$summary = [];
|
||||
$summary[] = t('Progress indicator: @progress_indicator', ['@progress_indicator' => $this->getSetting('progress_indicator')]);
|
||||
return $summary;
|
||||
}
|
||||
|
||||
|
|
@ -115,15 +115,15 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
$title = $this->fieldDefinition->getLabel();
|
||||
$description = $this->getFilteredDescription();
|
||||
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
$delta = 0;
|
||||
// Add an element for every existing item.
|
||||
foreach ($items as $item) {
|
||||
$element = array(
|
||||
$element = [
|
||||
'#title' => $title,
|
||||
'#description' => $description,
|
||||
);
|
||||
];
|
||||
$element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
|
||||
|
||||
if ($element) {
|
||||
|
|
@ -131,15 +131,15 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
if ($is_multiple) {
|
||||
// We name the element '_weight' to avoid clashing with elements
|
||||
// defined by widget.
|
||||
$element['_weight'] = array(
|
||||
$element['_weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight for row @number', array('@number' => $delta + 1)),
|
||||
'#title' => t('Weight for row @number', ['@number' => $delta + 1]),
|
||||
'#title_display' => 'invisible',
|
||||
// Note: this 'delta' is the FAPI #type 'weight' element's property.
|
||||
'#delta' => $max,
|
||||
'#default_value' => $item->_weight ?: $delta,
|
||||
'#weight' => 100,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$elements[$delta] = $element;
|
||||
|
|
@ -155,10 +155,10 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
if ($empty_single_allowed || $empty_multiple_allowed) {
|
||||
// Create a new empty item.
|
||||
$items->appendItem();
|
||||
$element = array(
|
||||
$element = [
|
||||
'#title' => $title,
|
||||
'#description' => $description,
|
||||
);
|
||||
];
|
||||
$element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
|
||||
if ($element) {
|
||||
$element['#required'] = ($element['#required'] && $delta == 0);
|
||||
|
|
@ -173,8 +173,8 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
$elements['#type'] = 'details';
|
||||
$elements['#open'] = TRUE;
|
||||
$elements['#theme'] = 'file_widget_multiple';
|
||||
$elements['#theme_wrappers'] = array('details');
|
||||
$elements['#process'] = array(array(get_class($this), 'processMultiple'));
|
||||
$elements['#theme_wrappers'] = ['details'];
|
||||
$elements['#process'] = [[get_class($this), 'processMultiple']];
|
||||
$elements['#title'] = $title;
|
||||
|
||||
$elements['#description'] = $description;
|
||||
|
|
@ -183,19 +183,19 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
// The field settings include defaults for the field type. However, this
|
||||
// widget is a base class for other widgets (e.g., ImageWidget) that may
|
||||
// act on field types without these expected settings.
|
||||
$field_settings = $this->getFieldSettings() + array('display_field' => NULL);
|
||||
$field_settings = $this->getFieldSettings() + ['display_field' => NULL];
|
||||
$elements['#display_field'] = (bool) $field_settings['display_field'];
|
||||
|
||||
// Add some properties that will eventually be added to the file upload
|
||||
// field. These are added here so that they may be referenced easily
|
||||
// through a hook_form_alter().
|
||||
$elements['#file_upload_title'] = t('Add a new file');
|
||||
$elements['#file_upload_description'] = array(
|
||||
$elements['#file_upload_description'] = [
|
||||
'#theme' => 'file_upload_help',
|
||||
'#description' => '',
|
||||
'#upload_validators' => $elements[0]['#upload_validators'],
|
||||
'#cardinality' => $cardinality,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $elements;
|
||||
|
|
@ -210,28 +210,28 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
// The field settings include defaults for the field type. However, this
|
||||
// widget is a base class for other widgets (e.g., ImageWidget) that may act
|
||||
// on field types without these expected settings.
|
||||
$field_settings += array(
|
||||
$field_settings += [
|
||||
'display_default' => NULL,
|
||||
'display_field' => NULL,
|
||||
'description_field' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
|
||||
$defaults = array(
|
||||
'fids' => array(),
|
||||
$defaults = [
|
||||
'fids' => [],
|
||||
'display' => (bool) $field_settings['display_default'],
|
||||
'description' => '',
|
||||
);
|
||||
];
|
||||
|
||||
// Essentially we use the managed_file type, extended with some
|
||||
// enhancements.
|
||||
$element_info = $this->elementInfo->getInfo('managed_file');
|
||||
$element += array(
|
||||
$element += [
|
||||
'#type' => 'managed_file',
|
||||
'#upload_location' => $items[$delta]->getUploadLocation(),
|
||||
'#upload_validators' => $items[$delta]->getUploadValidators(),
|
||||
'#value_callback' => array(get_class($this), 'value'),
|
||||
'#process' => array_merge($element_info['#process'], array(array(get_class($this), 'process'))),
|
||||
'#value_callback' => [get_class($this), 'value'],
|
||||
'#process' => array_merge($element_info['#process'], [[get_class($this), 'process']]),
|
||||
'#progress_indicator' => $this->getSetting('progress_indicator'),
|
||||
// Allows this field to return an array instead of a single value.
|
||||
'#extended' => TRUE,
|
||||
|
|
@ -242,29 +242,29 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
'#display_default' => $field_settings['display_default'],
|
||||
'#description_field' => $field_settings['description_field'],
|
||||
'#cardinality' => $cardinality,
|
||||
);
|
||||
];
|
||||
|
||||
$element['#weight'] = $delta;
|
||||
|
||||
// Field stores FID value in a single mode, so we need to transform it for
|
||||
// form element to recognize it correctly.
|
||||
if (!isset($items[$delta]->fids) && isset($items[$delta]->target_id)) {
|
||||
$items[$delta]->fids = array($items[$delta]->target_id);
|
||||
$items[$delta]->fids = [$items[$delta]->target_id];
|
||||
}
|
||||
$element['#default_value'] = $items[$delta]->getValue() + $defaults;
|
||||
|
||||
$default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value'];
|
||||
if (empty($default_fids)) {
|
||||
$file_upload_help = array(
|
||||
$file_upload_help = [
|
||||
'#theme' => 'file_upload_help',
|
||||
'#description' => $element['#description'],
|
||||
'#upload_validators' => $element['#upload_validators'],
|
||||
'#cardinality' => $cardinality,
|
||||
);
|
||||
];
|
||||
$element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
|
||||
$element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
|
||||
if ($cardinality != 1 && $cardinality != -1) {
|
||||
$element['#element_validate'] = array(array(get_class($this), 'validateMultipleCount'));
|
||||
$element['#element_validate'] = [[get_class($this), 'validateMultipleCount']];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
// Since file upload widget now supports uploads of more than one file at a
|
||||
// time it always returns an array of fids. We have to translate this to a
|
||||
// single fid, as field expects single value.
|
||||
$new_values = array();
|
||||
$new_values = [];
|
||||
foreach ($values as &$value) {
|
||||
foreach ($value['fids'] as $fid) {
|
||||
$new_value = $value;
|
||||
|
|
@ -311,7 +311,7 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
*
|
||||
* This method is assigned as a #value_callback in formElement() method.
|
||||
*/
|
||||
public static function value($element, $input = FALSE, FormStateInterface $form_state) {
|
||||
public static function value($element, $input, FormStateInterface $form_state) {
|
||||
if ($input) {
|
||||
// Checkboxes lose their value when empty.
|
||||
// If the display field is present make sure its unchecked value is saved.
|
||||
|
|
@ -324,11 +324,11 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
$return = ManagedFile::valueCallback($element, $input, $form_state);
|
||||
|
||||
// Ensure that all the required properties are returned even if empty.
|
||||
$return += array(
|
||||
'fids' => array(),
|
||||
$return += [
|
||||
'fids' => [],
|
||||
'display' => 1,
|
||||
'description' => '',
|
||||
);
|
||||
];
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
|
@ -353,7 +353,7 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
if ($total_uploaded_count > $field_storage->getCardinality()) {
|
||||
$keep = $newly_uploaded_count - $total_uploaded_count + $field_storage->getCardinality();
|
||||
$removed_files = array_slice($values['fids'], $keep);
|
||||
$removed_names = array();
|
||||
$removed_names = [];
|
||||
foreach ($removed_files as $fid) {
|
||||
$file = File::load($fid);
|
||||
$removed_names[] = $file->getFilename();
|
||||
|
|
@ -385,11 +385,11 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
|
||||
// Add the display field if enabled.
|
||||
if ($element['#display_field']) {
|
||||
$element['display'] = array(
|
||||
$element['display'] = [
|
||||
'#type' => empty($item['fids']) ? 'hidden' : 'checkbox',
|
||||
'#title' => t('Include file in display'),
|
||||
'#attributes' => array('class' => array('file-display')),
|
||||
);
|
||||
'#attributes' => ['class' => ['file-display']],
|
||||
];
|
||||
if (isset($item['display'])) {
|
||||
$element['display']['#value'] = $item['display'] ? '1' : '';
|
||||
}
|
||||
|
|
@ -398,33 +398,33 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$element['display'] = array(
|
||||
$element['display'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => '1',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Add the description field if enabled.
|
||||
if ($element['#description_field'] && $item['fids']) {
|
||||
$config = \Drupal::config('file.settings');
|
||||
$element['description'] = array(
|
||||
$element['description'] = [
|
||||
'#type' => $config->get('description.type'),
|
||||
'#title' => t('Description'),
|
||||
'#value' => isset($item['description']) ? $item['description'] : '',
|
||||
'#maxlength' => $config->get('description.length'),
|
||||
'#description' => t('The description may be used as the label of the link to the file.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Adjust the Ajax settings so that on upload and remove of any individual
|
||||
// file, the entire group of file fields is updated together.
|
||||
if ($element['#cardinality'] != 1) {
|
||||
$parents = array_slice($element['#array_parents'], 0, -1);
|
||||
$new_options = array(
|
||||
'query' => array(
|
||||
$new_options = [
|
||||
'query' => [
|
||||
'element_parents' => implode('/', $parents),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$field_element = NestedArray::getValue($form, $parents);
|
||||
$new_wrapper = $field_element['#id'] . '-ajax-wrapper';
|
||||
foreach (Element::children($element) as $key) {
|
||||
|
|
@ -440,9 +440,9 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
// functionality needed by the field widget. This submit handler, along with
|
||||
// the rebuild logic in file_field_widget_form() requires the entire field,
|
||||
// not just the individual item, to be valid.
|
||||
foreach (array('upload_button', 'remove_button') as $key) {
|
||||
$element[$key]['#submit'][] = array(get_called_class(), 'submit');
|
||||
$element[$key]['#limit_validation_errors'] = array(array_slice($element['#parents'], 0, -1));
|
||||
foreach (['upload_button', 'remove_button'] as $key) {
|
||||
$element[$key]['#submit'][] = [get_called_class(), 'submit'];
|
||||
$element[$key]['#limit_validation_errors'] = [array_slice($element['#parents'], 0, -1)];
|
||||
}
|
||||
|
||||
return $element;
|
||||
|
|
@ -477,22 +477,22 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
foreach ($element_children as $delta => $key) {
|
||||
if ($key != $element['#file_upload_delta']) {
|
||||
$description = static::getDescriptionFromElement($element[$key]);
|
||||
$element[$key]['_weight'] = array(
|
||||
$element[$key]['_weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#title' => $description ? t('Weight for @title', array('@title' => $description)) : t('Weight for new file'),
|
||||
'#title' => $description ? t('Weight for @title', ['@title' => $description]) : t('Weight for new file'),
|
||||
'#title_display' => 'invisible',
|
||||
'#delta' => $count,
|
||||
'#default_value' => $delta,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
// The title needs to be assigned to the upload field so that validation
|
||||
// errors include the correct widget label.
|
||||
$element[$key]['#title'] = $element['#title'];
|
||||
$element[$key]['_weight'] = array(
|
||||
$element[$key]['_weight'] = [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $delta,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -559,12 +559,12 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
|
|||
|
||||
// If there are more files uploaded via the same widget, we have to separate
|
||||
// them, as we display each file in its own widget.
|
||||
$new_values = array();
|
||||
$new_values = [];
|
||||
foreach ($submitted_values as $delta => $submitted_value) {
|
||||
if (is_array($submitted_value['fids'])) {
|
||||
foreach ($submitted_value['fids'] as $fid) {
|
||||
$new_value = $submitted_value;
|
||||
$new_value['fids'] = array($fid);
|
||||
$new_value['fids'] = [$fid];
|
||||
$new_values[] = $new_value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ImageField extends CckFieldPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class File extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'fid' => $this->t('File ID'),
|
||||
'uid' => $this->t('The {users}.uid who added the file. If set to 0, this file was added by an anonymous user.'),
|
||||
'filename' => $this->t('File name'),
|
||||
|
|
@ -85,7 +85,7 @@ class File extends DrupalSqlBase {
|
|||
'timestamp' => $this->t('The time that the file was added.'),
|
||||
'file_directory_path' => $this->t('The Drupal files path.'),
|
||||
'is_public' => $this->t('TRUE if the files directory is public otherwise FALSE.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Upload extends DrupalSqlBase {
|
|||
public function query() {
|
||||
$query = $this->select('upload', 'u')
|
||||
->distinct()
|
||||
->fields('u', array('nid', 'vid'));
|
||||
->fields('u', ['nid', 'vid']);
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
$query->addField('n', 'type');
|
||||
return $query;
|
||||
|
|
@ -37,7 +37,7 @@ class Upload extends DrupalSqlBase {
|
|||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$query = $this->select('upload', 'u')
|
||||
->fields('u', array('fid', 'description', 'list'))
|
||||
->fields('u', ['fid', 'description', 'list'])
|
||||
->condition('u.nid', $row->getSourceProperty('nid'))
|
||||
->orderBy('u.weight');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
|
@ -49,7 +49,7 @@ class Upload extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'fid' => $this->t('The file Id.'),
|
||||
'nid' => $this->t('The node Id.'),
|
||||
'vid' => $this->t('The version Id.'),
|
||||
|
|
@ -57,7 +57,7 @@ class Upload extends DrupalSqlBase {
|
|||
'description' => $this->t('The file description.'),
|
||||
'list' => $this->t('Whether the list should be visible on the node page.'),
|
||||
'weight' => $this->t('The file weight.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class UploadInstance extends DrupalSqlBase {
|
|||
$max_filesize = $this->variableGet('upload_uploadsize_default', 1);
|
||||
$max_filesize = $max_filesize ? $max_filesize . 'MB' : '';
|
||||
$file_extensions = $this->variableGet('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
|
||||
$return = array();
|
||||
$return = [];
|
||||
$values = $this->select('variable', 'v')
|
||||
->fields('v', ['name', 'value'])
|
||||
->condition('v.name', $variables, 'IN')
|
||||
|
|
@ -38,13 +38,13 @@ class UploadInstance extends DrupalSqlBase {
|
|||
->fetchAllKeyed();
|
||||
foreach ($node_types as $node_type) {
|
||||
$name = 'upload_' . $node_type;
|
||||
if (isset($values[$name])) {
|
||||
$enabled = unserialize($values[$name]);
|
||||
if ($enabled) {
|
||||
$return[$node_type]['node_type'] = $node_type;
|
||||
$return[$node_type]['max_filesize'] = $max_filesize;
|
||||
$return[$node_type]['file_extensions'] = $file_extensions;
|
||||
}
|
||||
// By default, file attachments in D6 are enabled unless upload_<type> is
|
||||
// false, so include types where the upload-variable is not set.
|
||||
$enabled = !isset($values[$name]) || unserialize($values[$name]);
|
||||
if ($enabled) {
|
||||
$return[$node_type]['node_type'] = $node_type;
|
||||
$return[$node_type]['max_filesize'] = $max_filesize;
|
||||
$return[$node_type]['file_extensions'] = $file_extensions;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,22 +55,22 @@ class UploadInstance extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'node_type' => array(
|
||||
return [
|
||||
'node_type' => [
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'node_type' => $this->t('Node type'),
|
||||
'max_filesize' => $this->t('Max filesize'),
|
||||
'file_extensions' => $this->t('File extensions'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class File extends DrupalSqlBase {
|
|||
|
||||
// Filter by scheme(s), if configured.
|
||||
if (isset($this->configuration['scheme'])) {
|
||||
$schemes = array();
|
||||
$schemes = [];
|
||||
// Accept either a single scheme, or a list.
|
||||
foreach ((array) $this->configuration['scheme'] as $scheme) {
|
||||
$schemes[] = rtrim($scheme) . '://';
|
||||
|
|
@ -93,7 +93,7 @@ class File extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'fid' => $this->t('File ID'),
|
||||
'uid' => $this->t('The {users}.uid who added the file. If set to 0, this file was added by an anonymous user.'),
|
||||
'filename' => $this->t('File name'),
|
||||
|
|
@ -101,7 +101,7 @@ class File extends DrupalSqlBase {
|
|||
'filemime' => $this->t('File MIME Type'),
|
||||
'status' => $this->t('The published status of a file.'),
|
||||
'timestamp' => $this->t('The time that the file was added.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\file\Plugin\views\argument;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\views\Plugin\views\argument\NumericArgument;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
|
@ -24,13 +23,6 @@ class Fid extends NumericArgument implements ContainerFactoryPluginInterface {
|
|||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity query factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* Constructs a Drupal\file\Plugin\views\argument\Fid object.
|
||||
*
|
||||
|
|
@ -42,13 +34,10 @@ class Fid extends NumericArgument implements ContainerFactoryPluginInterface {
|
|||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The entity query factory.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, QueryFactory $entity_query) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->entityQuery = $entity_query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,8 +48,7 @@ class Fid extends NumericArgument implements ContainerFactoryPluginInterface {
|
|||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity.manager'),
|
||||
$container->get('entity.query')
|
||||
$container->get('entity.manager')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -68,12 +56,12 @@ class Fid extends NumericArgument implements ContainerFactoryPluginInterface {
|
|||
* Override the behavior of titleQuery(). Get the filenames.
|
||||
*/
|
||||
public function titleQuery() {
|
||||
$fids = $this->entityQuery->get('file')
|
||||
$storage = $this->entityManager->getStorage('file');
|
||||
$fids = $storage->getQuery()
|
||||
->condition('fid', $this->value, 'IN')
|
||||
->execute();
|
||||
$controller = $this->entityManager->getStorage('file');
|
||||
$files = $controller->loadMultiple($fids);
|
||||
$titles = array();
|
||||
$files = $storage->loadMultiple($fids);
|
||||
$titles = [];
|
||||
foreach ($files as $file) {
|
||||
$titles[] = $file->getFilename();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class File extends FieldPluginBase {
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['link_to_file'] = array('default' => FALSE);
|
||||
$options['link_to_file'] = ['default' => FALSE];
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
|
@ -41,12 +41,12 @@ class File extends FieldPluginBase {
|
|||
* Provide link to file option
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['link_to_file'] = array(
|
||||
$form['link_to_file'] = [
|
||||
'#title' => $this->t('Link this field to download the file'),
|
||||
'#description' => $this->t("Enable to override this field's links."),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['link_to_file']),
|
||||
);
|
||||
];
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue