Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install field storage definitions for path and type #48

Open
wants to merge 3 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis-before-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ cd "$DRUPAL_TI_MODULES_PATH"
# Download Pathauto 8.x-1.x
git clone --depth 1 --branch 8.x-1.x https://github.com/md-systems/pathauto.git
git clone --depth 1 --branch 8.x-1.x http://git.drupal.org/project/token.git
git clone --depth 1 --branch 8.x-3.x http://git.drupal.org/project/ctools.git
17 changes: 10 additions & 7 deletions file_entity.install
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ function file_entity_schema() {
* Implements hook_install().
*/
function file_entity_install() {
$type_storage_definition = \Drupal::entityManager()->getFieldStorageDefinitions('file')['type'];
\Drupal::entityManager()->getStorage('file')->onFieldStorageDefinitionCreate($type_storage_definition);
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
$type_storage_definition = $entity_field_manager->getFieldStorageDefinitions('file')['type'];
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('type', 'file', 'file_entity', $type_storage_definition);

// If the pathauto module already exists, update the entity schema.
if (\Drupal::moduleHandler()->moduleExists('pathauto')) {
$path_storage_definition = $entity_field_manager->getFieldStorageDefinitions('file')['path'];
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('path', 'file', 'file_entity', $path_storage_definition);
}

// Set permissions.
$roles = user_roles();
foreach ($roles as $rid => $role) {
user_role_grant_permissions($rid, array('view files'));
}

// Configure default pathauto variables if it is currently installed.
if (\Drupal::moduleHandler()->moduleExists('pathauto')) {
\Drupal::configFactory()->getEditable('pathauto.pattern')->set('patterns.file.default', 'files/[file:name]')->save();
}

// Classify existing files according to the currently defined file types.
// Queue all files to be classified during cron runs using the Queue API.
$queue = \Drupal::queue('file_entity_type_determine');
Expand Down
99 changes: 0 additions & 99 deletions src/Plugin/pathauto/AliasType/FileAliasType.php

This file was deleted.

17 changes: 12 additions & 5 deletions src/Tests/FileEntityPathautoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Drupal\file_entity\Tests;

use Drupal\Component\Utility\Unicode;
use Drupal\pathauto\Entity\PathautoPattern;

/**
* Tests Pathauto support.
*
Expand All @@ -26,14 +29,18 @@ class FileEntityPathautoTest extends FileEntityTestBase {
* Tests Pathauto support.
*/
public function testPathauto() {
$this->config('pathauto.pattern')
->set('patterns.file.default', 'files/[file:name]')
->save();
$pattern = PathautoPattern::create([
'id' => Unicode::strtolower($this->randomMachineName()),
'type' => 'canonical_entities:file',
'pattern' => '/files/[file:name]',
'weight' => 0,
]);
$pattern->save();

$file = $this->createFileEntity();
$file = $this->createFileEntity(['filename' => 'example.png']);

$path = \Drupal::service('path.alias_storage')->load(array('source' => '/' . $file->urlInfo()->getInternalPath()));
$this->assertTrue($path, t('Alias for file found.'));
$this->assertEqual($path['alias'], '/files/example-png', t('Alias for file found.'));
}

}