Skip to content
Snippets Groups Projects
Commit ae9c6a4d authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Issue #3349736 by swentel: Drupal core date fields should not cause an error...

Issue #3349736 by swentel: Drupal core date fields should not cause an error when mapped to date property
parent ca4509e0
No related branches found
No related tags found
No related merge requests found
......@@ -226,3 +226,9 @@ function activitypub_node_view(array &$build, EntityInterface $entity, EntityVie
}
}
}
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle) {
return empty($needle) || strpos($haystack, $needle) !== false;
}
}
......@@ -222,7 +222,11 @@ abstract class TypePluginBase extends PluginBase implements TypePluginInterface,
switch ($property) {
case 'published':
$return = $this->dateFormatter->format($value[0]['value'], 'custom', 'Y-m-d\TH:i:s\Z');
$date_timestamp = $value[0]['value'];
if (!is_numeric($date_timestamp)) {
$date_timestamp = strtotime($value[0]['value']);
}
$return = $this->dateFormatter->format($date_timestamp, 'custom', 'Y-m-d\TH:i:s\Z');
break;
case 'name':
$return = trim($value[0]['value']);
......@@ -240,7 +244,7 @@ abstract class TypePluginBase extends PluginBase implements TypePluginInterface,
foreach ($value as $v) {
// Check if field_type is coming from media entity reference field
// type.
if ($field_type == 'entity_reference') {
if ($field_type == 'entity_reference') {
/** @var \Drupal\media\MediaInterface $media */
$media = $this->entityTypeManager->getStorage('media')->load($v['target_id']);
$fid = $media->getSource()->getSourceFieldValue($media);
......
......@@ -34,12 +34,7 @@ class FormatSetter implements HttpKernelInterface {
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response {
if ($request->headers->has('Accept')) {
$accept = $request->headers->get('Accept');
if (!function_exists('str_contains')) {
function str_contains (string $haystack, string $needle) {
return empty($needle) || strpos($haystack, $needle) !== false;
}
}
if (str_contains($accept, "application/activity+json") || str_contains($accept, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"')) {
if (str_contains($accept, "application/activity+json") || str_contains($accept, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"')) {
// @see https://www.drupal.org/project/activitypub/issues/3272176 why
// we are not using 'json'.
$request->setRequestFormat('activity_json');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment