You are here

class EmbedCode in Varbase Media 8.5

Same name and namespace in other branches
  1. 8.7 modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EmbedCode
  2. 8.6 modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EmbedCode
  3. 9.0.x modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EmbedCode

An Entity Browser widget for creating media entities from embed codes.

Plugin annotation


@EntityBrowserWidget(
  id = "embed_code",
  label = @Translation("Embed Code"),
  description = @Translation("Allows creation of media entities from embed codes."),
)

Hierarchy

  • class \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EntityFormProxy extends \Drupal\entity_browser\WidgetBase
    • class \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EmbedCode

Expanded class hierarchy of EmbedCode

File

modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php, line 16

Namespace

Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget
View source
class EmbedCode extends EntityFormProxy {

  /**
   * {@inheritdoc}
   */
  public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
    $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
    $form['input'] = [
      '#type' => 'textarea',
      '#placeholder' => $this
        ->t('Enter a URL...'),
      '#attributes' => [
        'class' => [
          'keyup-change',
        ],
      ],
      '#ajax' => [
        'event' => 'change',
        'wrapper' => 'entity',
        'method' => 'html',
        'callback' => [
          static::class,
          'ajax',
        ],
      ],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validate(array &$form, FormStateInterface $form_state) {
    $value = trim($this
      ->getInputValue($form_state));
    if ($value) {
      parent::validate($form, $form_state);
    }
    else {
      $form_state
        ->setError($form['widget'], $this
        ->t('You must enter a URL or embed code.'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EmbedCode::getForm public function Overrides EntityFormProxy::getForm
EmbedCode::validate public function Overrides EntityFormProxy::validate
EntityFormProxy::$helper protected property The media helper service.
EntityFormProxy::ajax public static function AJAX callback. Returns the rebuilt inline entity form.
EntityFormProxy::create public static function
EntityFormProxy::defaultConfiguration public function
EntityFormProxy::getAllowedBundles protected function Returns the bundles that this widget may use.
EntityFormProxy::getInputValue protected function Returns the current input value, if any.
EntityFormProxy::prepareEntities protected function
EntityFormProxy::submit public function
EntityFormProxy::__construct public function EntityFormProxy constructor.