|
|
@ -3,6 +3,7 @@ |
|
|
|
namespace Drupal\islandora\EventGenerator; |
|
|
|
namespace Drupal\islandora\EventGenerator; |
|
|
|
|
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
|
|
|
|
use Drupal\media_entity\Entity\Media; |
|
|
|
use Drupal\user\UserInterface; |
|
|
|
use Drupal\user\UserInterface; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -16,7 +17,7 @@ class EventGenerator implements EventGeneratorInterface { |
|
|
|
* {@inheritdoc} |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function generateCreateEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
public function generateCreateEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
return json_encode([ |
|
|
|
$event = [ |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"type" => "Create", |
|
|
|
"type" => "Create", |
|
|
|
"actor" => [ |
|
|
|
"actor" => [ |
|
|
@ -24,14 +25,20 @@ class EventGenerator implements EventGeneratorInterface { |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
], |
|
|
|
], |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
]); |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($entity instanceof Media) { |
|
|
|
|
|
|
|
$this->addAttachment($entity, $event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json_encode($event); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
return json_encode([ |
|
|
|
$event = [ |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"type" => "Update", |
|
|
|
"type" => "Update", |
|
|
|
"actor" => [ |
|
|
|
"actor" => [ |
|
|
@ -39,14 +46,20 @@ class EventGenerator implements EventGeneratorInterface { |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
], |
|
|
|
], |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
]); |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($entity instanceof Media) { |
|
|
|
|
|
|
|
$this->addAttachment($entity, $event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json_encode($event); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) { |
|
|
|
return json_encode([ |
|
|
|
$event = [ |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams", |
|
|
|
"type" => "Delete", |
|
|
|
"type" => "Delete", |
|
|
|
"actor" => [ |
|
|
|
"actor" => [ |
|
|
@ -54,7 +67,50 @@ class EventGenerator implements EventGeneratorInterface { |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
"id" => $user->toUrl()->setAbsolute()->toString(), |
|
|
|
], |
|
|
|
], |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
"object" => $entity->toUrl()->setAbsolute()->toString(), |
|
|
|
]); |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($entity instanceof Media) { |
|
|
|
|
|
|
|
$this->addAttachment($entity, $event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json_encode($event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Adds the 'attachment' info to the event array. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param \Drupal\media_entity\Entity\Media $entity |
|
|
|
|
|
|
|
* The entity that was updated. |
|
|
|
|
|
|
|
* @param array $event |
|
|
|
|
|
|
|
* Array of info to be serialized to jsonld. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected function addAttachment(Media $entity, array &$event) { |
|
|
|
|
|
|
|
if ($entity->hasField("field_image")) { |
|
|
|
|
|
|
|
$file = $entity->field_image->entity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elseif ($entity->hasField("field_file")) { |
|
|
|
|
|
|
|
$file = $entity->field_file->entity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
\Drupal::logger('islandora')->warning( |
|
|
|
|
|
|
|
"Cannot parse 'field_image' or 'field_file' from Media entity {$entity->id()}" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($file === null) { |
|
|
|
|
|
|
|
\Drupal::logger('islandora')->debug( |
|
|
|
|
|
|
|
"'field_image' or 'field_file' is null in Media entity {$entity->id()}" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$url = file_create_url($file->getFileUri()); |
|
|
|
|
|
|
|
$mime = $file->getMimeType(); |
|
|
|
|
|
|
|
$event['attachment'] = [ |
|
|
|
|
|
|
|
'url' => $url, |
|
|
|
|
|
|
|
'mediaType' => $mime, |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|