You are here

class FilefieldSourcesPreRenderCallback in FileField Sources 8

Hierarchy

Expanded class hierarchy of FilefieldSourcesPreRenderCallback

File

src/FilefieldSourcesPreRenderCallback.php, line 8

Namespace

Drupal\filefield_sources
View source
class FilefieldSourcesPreRenderCallback implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'preRender',
    ];
  }

  /**
   * #pre_render callback: hide sources if a file is currently uploaded.
   */
  public static function preRender($element) {

    // If we already have a file, we don't want to show the upload controls.
    if (!empty($element['#value']['fids'])) {
      foreach (Element::children($element) as $key) {
        if (!empty($element[$key]['#filefield_source'])) {
          $element[$key]['#access'] = FALSE;
        }
      }
    }
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FilefieldSourcesPreRenderCallback::preRender public static function #pre_render callback: hide sources if a file is currently uploaded.
FilefieldSourcesPreRenderCallback::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.