Explorar el Código

Work on upload widget

logicp hace 7 años
padre
commit
53b412028f
Se han modificado 4 ficheros con 75 adiciones y 48 borrados
  1. 27 0
      css/statusmessage.css
  2. 18 1
      js/statusmessage.js
  3. 30 47
      src/Form/StatusForm.php
  4. 0 0
      templates/status-form-element.html.twig

+ 27 - 0
css/statusmessage.css

@@ -40,3 +40,30 @@
   padding-left: 20%;
   transform: translate(5%, -150%);
 }
+
+#edit-mediatabs {
+  display: none;
+}
+
+.status-media-upload {
+  display: inline-block;
+  min-width: 32px;
+  min-height: 32px;
+  content: "Jigga";
+  margin-left: 4px;
+  background: url(/themes/kekistan/images/icons/mountains-picture.png) no-repeat;
+  background-size: contain;
+}
+
+#edit-media-upload {
+  display: inline-block;
+  max-width: 32px;
+  min-height: 32px;
+  position: relative;
+  transform: translate(-18px, -10px);
+  opacity: 0;
+}
+
+#edit-mediatabs + #ajax-wrapper {
+  display: inline-block;
+}

+ 18 - 1
js/statusmessage.js

@@ -68,9 +68,26 @@
       statusPostButton.addEventListener('click', function() {
         let textBox = document.getElementById('edit-message');
         textBox.value = "";
-      })
+      });
+
+
+
+
+
+
     }
   };
 
+  // let uploadButton = $('#edit-media-upload');
+  // uploadButton.hide();
+  // $('.status-media-upload').click(function() {
+  //   console.log('This is firing');
+  //   if (uploadButton.is(':visible')) {
+  //     uploadButton.hide();
+  //   } else {
+  //     uploadButton.show();
+  //   }
+  // });
+
 })(jQuery, Drupal, drupalSettings);
 

+ 30 - 47
src/Form/StatusForm.php

@@ -63,6 +63,7 @@ class StatusForm extends FormBase {
   public function buildForm(array $form, FormStateInterface $form_state) {
     /* @var $entity \Drupal\statusmessage\Entity\Status */
 
+
     $form['#attached']['library'][] = 'statusmessage/status';
 
     if (\Drupal::moduleHandler()->moduleExists('heartbeat')) {
@@ -88,18 +89,31 @@ class StatusForm extends FormBase {
       ],
     );
 
-//    $form['mediatabs'] = [
-//      '#type' => 'radios',
-////      '#description' => $this->t('User selectable feeds'),
-//      '#options' => $this->mediaTabs,
-////      '#ajax' => [
-////        'callback' => '::updateFeed',
-//////        'event' => 'onclick',
-////        'progress' => array(
-////          'type' => 'none',
-//////        'message' => t('Fetching feed'),
-////        ),
-//      ];
+    $form['mediatabs'] = [
+      '#type' => 'radios',
+//      '#description' => $this->t('User selectable feeds'),
+      '#prefix' => '<div class="status-media-upload"></div>',
+
+      '#options' => $this->mediaTabs,
+      '#theme' => 'status-form-element',
+//      '#ajax' => [
+//        'callback' => '::updateFeed',
+////        'event' => 'onclick',
+//        'progress' => array(
+//          'type' => 'none',
+////        'message' => t('Fetching feed'),
+//        ),
+      ];
+
+    $form['media'] = [
+      '#type' => 'managed_file',
+      '#upload_location' => 'public://statusmessage/',
+      '#states' => array(
+        'visible' => array(
+          ':input[name="File_type"]' => array('value' => t('Upload Your File')),
+        ),
+      ),
+    ];
 
 
     $form['post'] = array(
@@ -180,45 +194,14 @@ $stophere = null;
       $response->addCommand(new ClientCommand($url[0]));
 
       return $response;
-
-
     }
-
-//    if (!empty($this->statusTypeService)) {
-//      foreach ($this->statusTypeService->loadAll() as $type) {
-//        if (!$type->getMedia()) {
-//
-//          $userViewed = \Drupal::routeMatch()->getParameters()->get('user') === null ? \Drupal::currentUser()->id() : \Drupal::routeMatch()->getParameters()->get('user')->id();
-//
-//          if ($userViewed !== null) {
-//
-//            $statusEntity = Status::create([
-//              'type' => $type->id(),
-//              'uid' => \Drupal::currentUser()->id(),
-//              'recipient' => $userViewed
-//            ]);
-//
-//            $statusEntity->setMessage($form_state->getValue('message'));
-//            $statusEntity->save();
-//
-//            if (\Drupal::service('module_handler')->moduleExists('heartbeat')) {
-//
-////              $configManager = \Drupal::service('config.manager');
-//              $feedConfig = \Drupal::config('heartbeat_feed.settings');
-////              $feedConfig = $feedConfig = $configManager->get('heartbeat_feed.settings');
-//              $response = new AjaxResponse();
-//              $response->addCommand(new SelectFeedCommand($feedConfig->get('message')));
-//
-//              return $response;
-//            }
-//            break;
-//          }
-//        }
-//      }
-//    }
+    return null;
   }
+
+
   public function statusAjaxSubmit(array &$form, FormStateInterface $form_state) {
     $message = $form_state->getValue('message');
+    $file = $form_state->getValue('media');
     if (strlen(trim($message)) > 1) {
       preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $message, $match);
 

+ 0 - 0
templates/status-form-element.html.twig