SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/AttrEditorFilename.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16.  
  17. /**
  18.  * Specialised file selector input field for page attributes
  19.  */
  20. class AttrEditorFilename extends AttrEditor
  21. {
  22.  
  23. /**
  24.   * Return HTML for editing the attribute.
  25.   * Your attribute needs to return HTML for a single input element.
  26.   * The field name for the element needs to be 'value'.
  27.   *
  28.   * @param string $val The current value of the attribute
  29.   * @param string $attr_name The name of the attribute
  30.   **/
  31. public function render($val, $attr_name)
  32. {
  33. Fb::setData(['value' => $val]);
  34. return Fb::fileSelector('value', [], ['required' => true]);
  35. }
  36.  
  37.  
  38. /**
  39.   * If your class has script needs, load them in here.
  40.   * This is run on page load, not on ajax request.
  41.   **/
  42. public function needs()
  43. {
  44. }
  45.  
  46.  
  47. /**
  48.   * If you have any custom javascript to run, return it using this method.
  49.   *
  50.   * When your script runs, take a look at the $outer variable.
  51.   **/
  52. public function javascript($val, $attr_name)
  53. {
  54. return 'Fb.initAll($outer);';
  55. }
  56.  
  57. }
  58.