drApostropheMediaItemSelectPlugin - 1.0.4

Select an Apostrophe media item using a form widget

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

drApostropheMediaItemSelectPlugin

The drApostropheMediaItemSelectPlugin provides a widget and a validator that allow you to select a media item from the Apostrophe media library.

Installation

After installing the plugin, enable the plugin in your ProjectConfiguration class (in config/ProjectConfiguration.class.php

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins(array(
      // ...
      'drApostropheMediaItemSelectPlugin',
    ));
  }
}

Don't forget to run the

./symfony plugin:publish-assets

command so the plugin's JavaScript files will be made available from your web directory.

Form definition

In your form's configure method set the widget and the validator for the field that will eventually have the media item id set. Provide both the widget and the validator with a media_type option (which may be, video, image, pdf, etc.)

$this->setWidget('image_id', new aWidgetFormMediaItemSelect(array('media_type' => 'image')));
$this->setValidator('image_id', new aValidatorMediaItem(array('media_type' => 'image')));

Like the rest of Apostrophe, the widget depends on the jQuery library.

Usage in slots

When you use this widget to edit the information of a slot, you should explicitly load the JavaScript file on which the widget depends. Open your _editView.php and just before rendering the form, add this:

include_javascripts_for_form($form);

Configuration

The widget has several options, e.g. for changing the labels of the buttons:

$this->setWidget('image_id', new aWidgetFormMediaItemSelect(array(
  'media_type' => 'image',
  'select_media_button_label' => 'Select image',
  'clear_selection_button_label', 'Clear image',
  'clear_selection_confirmation_message' => 'Are you sure you want to clear the selection?',
));

TODO

  • Implement more parameters that are currently excepted by aMediaItemTable::getBrowseQuery().