Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
activitypub
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
activitypub
Commits
ca4509e0
Commit
ca4509e0
authored
1 year ago
by
Kristof De Jaeger
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3175472
by swentel: Support for other media types (audio / video)
parent
9aaad695
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+3
-2
3 additions, 2 deletions
README.md
src/Plugin/activitypub/type/DynamicTypes.php
+21
-4
21 additions, 4 deletions
src/Plugin/activitypub/type/DynamicTypes.php
src/Services/Type/TypePluginBase.php
+39
-4
39 additions, 4 deletions
src/Services/Type/TypePluginBase.php
with
63 additions
and
10 deletions
README.md
+
3
−
2
View file @
ca4509e0
...
...
@@ -60,11 +60,12 @@ when enabling this module, which are the 'Accept', 'Follow', 'Delete', 'Undo'
and 'Inbox reply' types. A "Note" example is also installed with basic
configuration but is not enabled yet since this depends on your setup.
6.
Create your own configuration
-
Select 'Type plugin', only dynamic types is currently available
-
Select 'Type plugin'. Public message is the plugin that allows mapping
content fields with AP properties.
-
Select the content type which you want to map
-
Select the activity (See footnotes underneath)
-
Select the object (use Note if you do not want to populate a title)
-
Map properties to the content type fields
-
Map properties to the content type fields
.
7.
When saved, go to the content type you selected. You can now select the
entity which will process this node in the 'ActivityPub outbox' fieldset.
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/activitypub/type/DynamicTypes.php
+
21
−
4
View file @
ca4509e0
...
...
@@ -77,7 +77,11 @@ class DynamicTypes extends TypePluginBase {
'summary'
=>
'Summary'
,
'object'
=>
'Like/Announce/Follow target'
,
'inReplyTo'
=>
'Reply link'
,
'attachment'
=>
'Image attachment'
,
// 'attachment' was originally reserved for 'images' only, but attachments
// can also contain other media types.
'attachment'
=>
[
'label'
=>
'Image attachment'
,
'property'
=>
'attachment'
],
'attachment_2'
=>
[
'label'
=>
'Video attachment'
,
'property'
=>
'attachment'
],
'attachment_3'
=>
[
'label'
=>
'Audio attachment'
,
'property'
=>
'attachment'
],
];
}
...
...
@@ -106,7 +110,8 @@ class DynamicTypes extends TypePluginBase {
];
$properties
=
$this
->
getProperties
(
$this
->
getConfiguration
()[
'object'
]);
foreach
(
$properties
as
$property
=>
$label
)
{
foreach
(
$properties
as
$property
=>
$info
)
{
$label
=
is_array
(
$info
)
?
$info
[
'label'
]
:
$info
;
$form
[
'field_mapping'
][]
=
[
'property'
=>
[
'#type'
=>
'value'
,
...
...
@@ -138,8 +143,20 @@ class DynamicTypes extends TypePluginBase {
if
(
!
empty
(
$mapping
[
'field_name'
]))
{
if
(
$entity
->
hasField
(
$mapping
[
'field_name'
])
&&
(
$value
=
$entity
->
get
(
$mapping
[
'field_name'
])
->
getValue
()))
{
$field_type
=
$entity
->
get
(
$mapping
[
'field_name'
])
->
getFieldDefinition
()
->
getType
();
if
(
$v
=
$this
->
getValue
(
$mapping
[
'property'
],
$value
,
$field_type
))
{
$object
[
$mapping
[
'property'
]]
=
$v
;
$property
=
$mapping
[
'property'
];
// 'attachment' was originally reserved for 'images' only, but
// attachments can also contain other media types like video and
// audio.
if
(
str_contains
(
$property
,
'attachment_'
))
{
$property
=
'attachment'
;
}
if
(
$v
=
$this
->
getValue
(
$property
,
$value
,
$field_type
))
{
if
(
!
isset
(
$object
[
$property
]))
{
$object
[
$property
]
=
$v
;
}
else
{
$object
[
$property
]
=
array_merge
(
$v
,
$object
[
$property
]);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Services/Type/TypePluginBase.php
+
39
−
4
View file @
ca4509e0
...
...
@@ -251,10 +251,11 @@ abstract class TypePluginBase extends PluginBase implements TypePluginInterface,
/** @var \Drupal\file\FileInterface $file */
$file
=
$this
->
entityTypeManager
->
getStorage
(
'file'
)
->
load
(
$v
[
'target_id'
]);
}
$type
=
$this
->
getMediaType
(
$file
);
$return
[]
=
(
object
)
[
'type'
=>
'Image'
,
'type'
=>
$type
,
'mediaType'
=>
$file
->
getMimeType
(),
'url'
=>
$this
->
getFileUrl
(
$file
),
'url'
=>
$this
->
getFileUrl
(
$file
,
$type
),
];
}
break
;
...
...
@@ -263,20 +264,54 @@ abstract class TypePluginBase extends PluginBase implements TypePluginInterface,
return
$return
;
}
/**
* Get the media type.
*
* @param \Drupal\file\FileInterface $file
*
* @return string
*/
protected
function
getMediaType
(
FileInterface
$file
)
{
$type
=
'Document'
;
switch
(
$file
->
getMimeType
())
{
case
'image/jpg'
:
case
'image/jpeg'
:
case
'image/webp'
:
case
'image/png'
:
case
'image/gif'
:
$type
=
'Image'
;
break
;
case
'video/mpeg'
:
case
'video/mp4'
:
case
'video/quicktime'
:
case
'video/ogg'
:
$type
=
'Video'
;
break
;
case
'audio/ogg'
:
case
'audio/mp3'
:
$type
=
'Audio'
;
break
;
}
return
$type
;
}
/**
* Gets the file URL.
*
* @param \Drupal\file\FileInterface $file
* @param string $type
*
* @return string
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected
function
getFileUrl
(
FileInterface
$file
)
{
protected
function
getFileUrl
(
FileInterface
$file
,
string
$type
)
{
$config
=
$this
->
configFactory
->
get
(
'activitypub.settings'
);
$attachment_content_style
=
$config
->
get
(
'attachment_content_style'
);
if
(
!
empty
(
$attachment_content_style
))
{
if
(
!
empty
(
$attachment_content_style
)
&&
$type
==
'Image'
)
{
/** @var \Drupal\image\ImageStyleInterface $image_style */
$storage
=
$this
->
entityTypeManager
->
getStorage
(
'image_style'
);
$image_style
=
$storage
->
load
(
$attachment_content_style
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment