Explorar el Código

Fixing status form

logicp hace 7 años
padre
commit
b42827073b
Se han modificado 1 ficheros con 7 adiciones y 4 borrados
  1. 7 4
      src/Form/StatusForm.php

+ 7 - 4
src/Form/StatusForm.php

@@ -221,7 +221,7 @@ $stophere = null;
     if (strlen(trim($message)) > 1) {
       preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $message, $match);
       if (strpos($message, 'twitter')) {
-        if ($this->previewGenerator !== NULL && !empty($match) && array_values($match)[0] !== NULL) {
+        if ($this->markupgenerator !== NULL && !empty($match) && array_values($match)[0] !== NULL) {
           $url = is_array(array_values($match)[0]) ? array_values(array_values($match)[0])[0] : array_values($match)[0];
           $statusTwitter = new StatusTwitter($url);
           $nid = $statusTwitter->sendRequest();
@@ -230,7 +230,7 @@ $stophere = null;
       }
       else {
         if (strpos($message, 'youtube') || strpos($message, 'youtu.be')) {
-          if ($this->previewGenerator !== NULL && !empty($match) && array_values($match)[0] !== NULL) {
+          if ($this->markupgenerator !== NULL && !empty($match) && array_values($match)[0] !== NULL) {
             $url = is_array(array_values($match)[0]) ? array_values(array_values($match)[0])[0] : array_values($match)[0];
             $statusYoutube = new StatusYoutube($url);
             $nid = $statusYoutube->generateNode();
@@ -240,8 +240,9 @@ $stophere = null;
       }
 
       if ($nid === NULL && !empty($this->statusTypeService)) {
+        $statusCreated = false;
         foreach ($this->statusTypeService->loadAll() as $type) {
-          if (!$type->getMedia()) {
+          if (!$statusCreated && !$type->getMedia()) {
 
             $userViewed = \Drupal::routeMatch()
               ->getParameters()
@@ -260,7 +261,9 @@ $stophere = null;
               ]);
 
               $statusEntity->setMessage($message);
-              $statusEntity->save();
+              if ($statusEntity->save()) {
+                $statusCreated = TRUE;
+              }
             }
           }
         }