Esempio n. 1
0
 /**
  * Form API callback. Retrieves the value for the file_generic field element.
  *
  * This method is assigned as a #value_callback in formElement() method.
  *
  * @param array $element
  *   The element.
  * @param array|bool $input
  *   An array of input values, or FALSE.
  * @param FormStateInterface $form_state
  *   The form state.
  *
  * @return array|mixed|null
  *   An array values for the widget.
  */
 public static function value($element, $input = FALSE, FormStateInterface $form_state)
 {
     if ($input) {
         // Checkboxes lose their value when empty.
         // If the display field is present make sure its unchecked value is saved.
         if (empty($input['display'])) {
             $input['display'] = $element['#display_field'] ? 0 : 1;
         }
     }
     // We depend on the managed file element to handle uploads.
     $return = EmbridgeAsset::valueCallback($element, $input, $form_state);
     // Ensure that all the required properties are returned even if empty.
     $return += array('fids' => array(), 'display' => 1, 'description' => '');
     return $return;
 }
 /**
  * Pre render hook for asset element.
  *
  * Disables the remove button after running the normal pre render function.
  * There's a bug with the remove button post search, and users can just delete
  * the image if they need to remove it from the editor.
  *
  * @param array $element
  *   The element.
  *
  * @return array
  *   Altered element.
  */
 public static function preRenderAssetElement(array $element)
 {
     $element = EmbridgeAsset::preRenderEmbridgeAsset($element);
     $element['remove_button']['#access'] = FALSE;
     return $element;
 }