Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Issue forks
linkit-2886455
Commits
1084887a
Commit
1084887a
authored
Mar 03, 2018
by
Janez Urevc
Committed by
Emil Stjerneman
Mar 03, 2018
Browse files
Issue
#2930171
by slashrsm, anon: Support core Media entity
parent
0a644829
Changes
8
Hide whitespace changes
Inline
Side-by-side
linkit.info.yml
View file @
1084887a
...
...
@@ -6,4 +6,3 @@ core: 8.x
configure
:
entity.linkit_profile.collection
test_dependencies
:
-
imce
-
media_entity
\ No newline at end of file
src/Plugin/Linkit/Substitution/Media.php
View file @
1084887a
...
...
@@ -69,14 +69,14 @@ class Media extends PluginBase implements SubstitutionInterface, ContainerFactor
public
function
getUrl
(
EntityInterface
$entity
)
{
$url
=
new
GeneratedUrl
();
/** @var \Drupal\media
_entity
\Media
Bundl
eInterface $media_
bundl
e */
$media_
bundle
=
$this
->
entityTypeManager
->
getStorage
(
'media_bundle'
)
->
load
(
$entity
->
bundle
())
;
/** @var \Drupal\media\Media
Typ
eInterface $media_
typ
e */
$media_
type
=
$entity
->
get
(
'bundle'
)
->
entity
;
// Default to the canonical URL if the bundle doesn't have a source field.
if
(
empty
(
$media_
bundle
->
get
Type
Configuration
()[
'source_field'
]))
{
if
(
empty
(
$media_
type
->
getSource
()
->
getConfiguration
()[
'source_field'
]))
{
return
$entity
->
toUrl
(
'canonical'
)
->
toString
(
TRUE
);
}
$source_field
=
$media_
bundle
->
get
Type
Configuration
()[
'source_field'
];
$source_field
=
$media_
type
->
getSource
()
->
getConfiguration
()[
'source_field'
];
/** @var \Drupal\file\FileInterface $file */
$file
=
$entity
->
{
$source_field
}
->
entity
;
$url
->
setGeneratedUrl
(
file_create_url
(
$file
->
getFileUri
()));
...
...
@@ -94,7 +94,7 @@ class Media extends PluginBase implements SubstitutionInterface, ContainerFactor
* If the plugin is applicable.
*/
public
static
function
isApplicable
(
EntityTypeInterface
$entity_type
)
{
return
$entity_type
->
entityClassImplements
(
'Drupal\media
_entity
\MediaInterface'
);
return
$entity_type
->
entityClassImplements
(
'Drupal\media\MediaInterface'
);
}
}
tests/linkit_media_test/config/schema/linkit_media_test.schema.yml
deleted
100644 → 0
View file @
0a644829
media_entity.bundle.type.test_type
:
type
:
mapping
label
:
'
Test
type
configuration'
mapping
:
source_field
:
type
:
string
label
:
'
Field
with
source
information'
tests/linkit_media_test/config/schema/linkit_test.schema.yml
deleted
100644 → 0
View file @
0a644829
# Schema for the configuration files of the Linkit test module.
# Plugin \Drupal\linkit_test\Plugin\Linkit\Matcher\ConfigurableDummyMatcher
linkit.matcher.configurable_dummy_matcher
:
type
:
linkit.matcher
mapping
:
dummy_setting
:
type
:
boolean
tests/linkit_media_test/linkit_media_test.info.yml
deleted
100644 → 0
View file @
0a644829
name
:
'
Linkit
media
test
module'
description
:
'
Support
module
for
Linkit
media
testing.'
package
:
Testing
type
:
module
core
:
8.x
dependencies
:
-
linkit:linkit
-
drupal:field
-
drupal:text
-
media_entity:media_entity
tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php
deleted
100644 → 0
View file @
0a644829
<?php
namespace
Drupal\linkit_media_test\Plugin\MediaEntity\Type
;
use
Drupal\media_entity
\
Plugin\MediaEntity\Type\Generic
;
/**
* Provides generic media type.
*
* @MediaType(
* id = "test_type",
* label = @Translation("Test type"),
* description = @Translation("Test media type.")
* )
*/
class
TestType
extends
Generic
{
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
()
{
return
[
'source_field'
=>
'field_media_file'
,
];
}
}
tests/src/Kernel/Matchers/FileMatcherTest.php
View file @
1084887a
...
...
@@ -4,7 +4,6 @@ namespace Drupal\Tests\linkit\Kernel\Matchers;
use
Drupal\file\Entity\File
;
use
Drupal\Tests\linkit\Kernel\LinkitKernelTestBase
;
use
Drupal\user\Entity\User
;
/**
* Tests file matcher.
...
...
tests/src/Kernel/SubstitutionPluginTest.php
View file @
1084887a
...
...
@@ -3,14 +3,13 @@
namespace
Drupal\Tests\linkit\Kernel
;
use
Drupal\entity_test
\
Entity\EntityTest
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\file\Entity\File
;
use
Drupal\linkit\Plugin\Linkit\Substitution\Canonical
as
CanonicalSubstitutionPlugin
;
use
Drupal\linkit\Plugin\Linkit\Substitution\File
as
FileSubstitutionPlugin
;
use
Drupal\linkit\Plugin\Linkit\Substitution\Media
as
MediaSubstitutionPlugin
;
// use Drupal\media_entity\Entity\Media;
// use Drupal\media_entity\Entity\MediaBundle;
use
Drupal\media\Entity\Media
;
use
Drupal\media\Entity\MediaType
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
/**
* Tests the substitution plugins.
...
...
@@ -43,10 +42,9 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
public
static
$modules
=
[
'file'
,
'entity_test'
,
//
'media
_entity
',
'media'
,
'image'
,
'field'
,
// 'linkit_media_test',
];
/**
...
...
@@ -59,11 +57,43 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
$this
->
installEntitySchema
(
'file'
);
$this
->
installEntitySchema
(
'entity_test'
);
//
$this->installEntitySchema('media');
//
$this->installEntitySchema('media_
bundl
e');
$this
->
installEntitySchema
(
'media'
);
$this
->
installEntitySchema
(
'media_
typ
e'
);
$this
->
installEntitySchema
(
'field_storage_config'
);
$this
->
installEntitySchema
(
'field_config'
);
$this
->
installSchema
(
'file'
,
[
'file_usage'
]);
unset
(
$GLOBALS
[
'config'
][
'system.file'
]);
\
Drupal
::
configFactory
()
->
getEditable
(
'system.file'
)
->
set
(
'default_scheme'
,
'public'
)
->
save
();
}
/**
* {@inheritdoc}
*/
public
function
register
(
ContainerBuilder
$container
)
{
parent
::
register
(
$container
);
$container
->
register
(
'stream_wrapper.public'
,
'Drupal\Core\StreamWrapper\PublicStream'
)
->
addTag
(
'stream_wrapper'
,
[
'scheme'
=>
'public'
]);
}
/**
* {@inheritdoc}
*/
protected
function
setUpFilesystem
()
{
$public_file_directory
=
$this
->
siteDirectory
.
'/files'
;
require_once
'core/includes/file.inc'
;
mkdir
(
$this
->
siteDirectory
,
0775
);
mkdir
(
$this
->
siteDirectory
.
'/files'
,
0775
);
mkdir
(
$this
->
siteDirectory
.
'/files/config/'
.
CONFIG_SYNC_DIRECTORY
,
0775
,
TRUE
);
$this
->
setSetting
(
'file_public_path'
,
$public_file_directory
);
$GLOBALS
[
'config_directories'
]
=
[
CONFIG_SYNC_DIRECTORY
=>
$this
->
siteDirectory
.
'/files/config/sync'
,
];
}
/**
...
...
@@ -107,30 +137,22 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
/**
* Test the media substitution.
*/
/*
public
function
testMediaSubstitution
()
{
// Set up media bundle and fields.
M
edia
Bundl
e::create([
$m
edia
_type
=
MediaTyp
e
::
create
([
'label'
=>
'test'
,
'id'
=>
'test'
,
'description' => 'test bundle.',
'type' => 'test_type',
])->save();
FieldStorageConfig::create([
'field_name' => 'field_media_file',
'entity_type' => 'media',
'type' => 'file',
'settings' => [],
])->save();
FieldConfig::create([
'entity_type' => 'media',
'bundle' => 'test',
'field_name' => 'field_media_file',
'label' => 'Media field',
'settings' => [
'file_extensions' => 'txt',
],
'description'
=>
'Test type.'
,
'source'
=>
'file'
,
]);
$media_type
->
save
();
$source_field
=
$media_type
->
getSource
()
->
createSourceField
(
$media_type
);
$source_field
->
getFieldStorageDefinition
()
->
save
();
$source_field
->
save
();
$media_type
->
set
(
'source_configuration'
,
[
'source_field'
=>
$source_field
->
getName
(),
])
->
save
();
$file
=
File
::
create
([
'uid'
=>
1
,
'filename'
=>
'druplicon.txt'
,
...
...
@@ -139,9 +161,10 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
'status'
=>
FILE_STATUS_PERMANENT
,
]);
$file
->
save
();
$media
=
Media
::
create
([
'bundle'
=>
'test'
,
'field_media_file'
=> ['target_id' => $file->id()],
$source_field
->
getName
()
=>
[
'target_id'
=>
$file
->
id
()],
]);
$media
->
save
();
...
...
@@ -154,6 +177,5 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
$entity_type
=
$this
->
entityTypeManager
->
getDefinition
(
'file'
);
$this
->
assertFalse
(
MediaSubstitutionPlugin
::
isApplicable
(
$entity_type
),
'The entity type File is not applicable the media substitution.'
);
}
*/
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment