parametri espliciti
This commit is contained in:
parent
f2183d21de
commit
f765a4b00c
1 changed files with 6 additions and 3 deletions
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
const PARAGRAPH = 'audio';
|
||||||
|
const LINKFIELD = 'field_audio_link';
|
||||||
function isArchive(string $url): bool {
|
function isArchive(string $url): bool {
|
||||||
$pos = strpos($url, "archive.org/");
|
$pos = strpos($url, "archive.org/");
|
||||||
if($pos === FALSE) {
|
if($pos === FALSE) {
|
||||||
|
@ -28,18 +31,18 @@ function normalizeArchive(string $url) {
|
||||||
*/
|
*/
|
||||||
function audiofix_ror_paragraph_presave(Drupal\Core\Entity\EntityInterface $entity) {
|
function audiofix_ror_paragraph_presave(Drupal\Core\Entity\EntityInterface $entity) {
|
||||||
// per i paragraph, getType() === bundle().
|
// per i paragraph, getType() === bundle().
|
||||||
if($entity->bundle() !== 'audio') { // audio e' il nome del nostro paragraph type
|
if($entity->bundle() !== PARAGRAPH) { // audio e' il nome del nostro paragraph type
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// campi utili: field_audio_link e field_durata
|
// campi utili: field_audio_link e field_durata
|
||||||
$link = $entity->get('field_audio_link')->getValue();
|
$link = $entity->get(LINKFIELD)->getValue();
|
||||||
if(count($link) == 0) { return; }
|
if(count($link) == 0) { return; }
|
||||||
$link = $link[0]['uri'];
|
$link = $link[0]['uri'];
|
||||||
if(is_string($link) && isArchive($link)) {
|
if(is_string($link) && isArchive($link)) {
|
||||||
$norm = normalizeArchive($link);
|
$norm = normalizeArchive($link);
|
||||||
if($norm !== $link) {
|
if($norm !== $link) {
|
||||||
\Drupal::logger('audiofix_ror')->notice('Aggiornato da :old a :new', array(":old" => $link, ":new" => $norm));
|
\Drupal::logger('audiofix_ror')->notice('Aggiornato da :old a :new', array(":old" => $link, ":new" => $norm));
|
||||||
$entity->set('field_audio_link', $norm);
|
$entity->set(LINKFIELD, $norm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue