Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit b9993dd

Browse files
committed
Merge branch '8.x-2.x' of git.drupal.org:project/file_entity into 8.x-2.x
2 parents fe199b3 + d80358a commit b9993dd

File tree

9 files changed

+87
-15
lines changed

9 files changed

+87
-15
lines changed

config/schema/file_entity.schema.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,23 @@ action.configuration.file_temporary_action:
119119
field.widget.settings.file_editable:
120120
type: field.widget.settings.file_generic
121121
label: 'File format settings'
122+
123+
field.widget.settings.file_entity_browser:
124+
type: mapping
125+
label: 'File entity browser settings'
126+
mapping:
127+
entity_browser:
128+
type: string
129+
label: 'Entity browser'
130+
field_widget_edit:
131+
type: boolean
132+
label: 'Display edit button'
133+
field_widget_remove:
134+
type: boolean
135+
label: 'Display remove button'
136+
open:
137+
type: boolean
138+
label: 'Show widget details as open by default'
139+
view_mode:
140+
type: string
141+
label: 'View mode'

file_entity.info.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ dependencies:
99
- views
1010
- image
1111
configure: file_entity.settings
12+
test_dependencies:
13+
- pathauto

file_entity.install

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ function file_entity_uninstall() {
8888
// Remove the added column to the core {file_managed} table.
8989
db_drop_field('file_managed', 'type');
9090
}
91+
/**
92+
* Update existing bogus entries for File types Document.
93+
*/
94+
function file_entity_update_8002(&$sandbox) {
95+
foreach (\Drupal::configFactory()->listAll('file_entity') as $config_name) {
96+
$config = \Drupal::configFactory()->getEditable($config_name);
97+
$config->set('mimetypes', str_replace("\r", "", $config->get('mimetypes')));
98+
$config->save();
99+
}
100+
}

file_entity.services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
file_entity.route_subscriber:
3+
class: Drupal\file_entity\Routing\RouteSubscriber
4+
tags:
5+
- { name: event_subscriber }

src/Form/FileSettingsForm.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66

77
namespace Drupal\file_entity\Form;
8-
use Drupal\Core\Form\FormBase;
8+
9+
use Drupal\Core\Form\ConfigFormBase;
910
use Drupal\Core\Form\FormStateInterface;
1011

1112
/**
1213
* Class FileSettingsForm
1314
* @package Drupal\file_entity\Form
1415
*/
15-
class FileSettingsForm extends FormBase {
16+
class FileSettingsForm extends ConfigFormBase {
1617

1718
/**
1819
* Returns a unique string identifying the form.
@@ -24,6 +25,15 @@ public function getFormId() {
2425
return 'file_settings';
2526
}
2627

28+
/**
29+
* {@inheritdoc}
30+
*/
31+
protected function getEditableConfigNames() {
32+
return [
33+
'file_entity.settings',
34+
];
35+
}
36+
2737
/**
2838
* {@inheritdoc}
2939
*/
@@ -33,7 +43,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
3343
'#title' => t('Maximum upload size'),
3444
'#default_value' => \Drupal::config('file_entity.settings')->get('max_filesize'),
3545
'#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 max limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))),
36-
'#element_validate' => '\Drupal\file\Plugin\Field\FieldType\FileItem::validateMaxFilesize',
46+
'#element_validate' => ['\Drupal\file\Plugin\Field\FieldType\FileItem::validateMaxFilesize'],
3747
'#size' => 10,
3848
);
3949

@@ -42,7 +52,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
4252
'#title' => t('Default allowed file extensions'),
4353
'#default_value' => \Drupal::config('file_entity.settings')->get('default_allowed_extensions'),
4454
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
45-
'#element_validate' => '\Drupal\file\Plugin\Field\FieldType\FileItem::validateExtensions',
55+
'#element_validate' => ['\Drupal\file\Plugin\Field\FieldType\FileItem::validateExtensions'],
4656
'#maxlength' => NULL,
4757
);
4858

src/Form/FileTypeForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
131131
// Convert multi-line string to array before copying.
132132
// This may be called multiple times and exectued only if it is a string.
133133
if (is_string($form_state->getValue('mimetypes'))) {
134-
$form_state->setValue('mimetypes', explode("\n", $form_state->getValue('mimetypes')));
134+
$form_state->setValue('mimetypes', explode("\n", str_replace("\r", "", $form_state->getValue('mimetypes'))));
135135
}
136136
parent::copyFormValuesToEntity($entity, $form, $form_state);
137137
}

src/Plugin/Field/FieldWidget/FileEntityBrowser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class FileEntityBrowser extends EntityReference {
4545
*/
4646
public static function defaultSettings() {
4747
$settings = parent::defaultSettings();
48+
49+
// These settings are hidden.
50+
unset($settings['field_widget_display']);
51+
unset($settings['field_widget_display_settings']);
52+
4853
$settings['view_mode'] = 'thumbnail';
4954
return $settings;
5055
}

src/Routing/RouteSubscriber.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\file_entity\Routing\RouteSubscriber.
6+
*/
7+
8+
namespace Drupal\file_entity\Routing;
9+
10+
use Drupal\Core\Routing\RouteSubscriberBase;
11+
use Symfony\Component\Routing\RouteCollection;
12+
13+
/**
14+
* Listens to the dynamic route events.
15+
*/
16+
class RouteSubscriber extends RouteSubscriberBase {
17+
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function alterRoutes(RouteCollection $collection) {
22+
// The usage view should be shown in the admin theme.
23+
if ($route = $collection->get('view.file_entity_files.usage')) {
24+
$route->setOption('_admin_route', TRUE);
25+
}
26+
}
27+
}

src/Tests/FileEntityNormalizerTest.php renamed to tests/src/Kernel/FileEntityNormalizerTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
/**
33
* @file
4-
* Contains \Drupal\file_entity\Tests\FileEntityNormalizerTest.
4+
* Contains \Drupal\Tests\file_entity\Kernel\FileEntityNormalizerTest.
55
*/
66

7-
namespace Drupal\file_entity\Tests;
7+
namespace Drupal\Tests\file_entity\Kernel;
88

99
use Drupal\Core\StreamWrapper\PublicStream;
1010
use Drupal\field\Entity\FieldConfig;
@@ -13,7 +13,7 @@
1313
use Drupal\file_entity\Entity\FileType;
1414
use Drupal\node\Entity\Node;
1515
use Drupal\node\Entity\NodeType;
16-
use Drupal\simpletest\KernelTestBase;
16+
use Drupal\KernelTests\KernelTestBase;
1717
use Drupal\system\Tests\Routing\MockRouteProvider;
1818
use Symfony\Component\Routing\Route;
1919
use Symfony\Component\Routing\RouteCollection;
@@ -45,13 +45,6 @@ class FileEntityNormalizerTest extends KernelTestBase {
4545
'system',
4646
);
4747

48-
/**
49-
* Disable strict schema checking until schema is updated.
50-
*
51-
* @todo Update schema and remove this.
52-
*/
53-
protected $strictConfigSchema = FALSE;
54-
5548
/**
5649
* {@inheritdoc}
5750
*/

0 commit comments

Comments
 (0)