Jump to content

Developer Documentation

core/MetaData

What it is

The MetaData extension type is a very generic extension type that, at its core, is designed to facilitate the addition of meta data associated with content items. If your application does not have any content items, then this extension type will not be of use to you.

The best way to see how you might use this extension is to review some existing implementations, including the core extensions FeaturedComments (which allows moderators to feature comments within individual content items) and ContentMessages (which allows moderators to add generic messages to content items). Note, however, that the extension type is abstract and you can use it to add any type of meta data that will be associated with content items.

How to use

When you create a new instance of this extension there are no methods defined, and indeed you are not explicitly required to define any. It is often beneficial, however, to add helper methods related to the type of meta data you are adding. For instance, if you were creating a MetaData extension that would allow moderators to add regular members as moderators for individual content items, you may want to create helper methods for canAddModerator(), isModerator(), removeModerator() and so on. Ultimately, however, it is up to you.

Content Items must implement the \IPS\Content\MetaData interface to make use of MetaData extensions. You must add a column to your content item database table to store meta data references, and then you must map this column in the $databaseColumnMap class property for your content item class with an array key 'meta_data'. Your content item class must implement the method supportedMetaDataTypes() which will define which meta data types it supports, as well.

    /**
     * Supported Meta Data Types
     *
     * @return    array
     */
    public static function supportedMetaDataTypes()
    {
        return array( 'core_ContentMessages' );
    }

Afterwards, the meta data will be maintained automatically (i.e. if the content item is deleted, the meta data will automatically be deleted as well).

Several helper methods will become available to you within your content item class once you have taken these steps.

    /**
     * Check if this content has meta data
     *
     * @return    bool
     * @throws    \BadMethodCallException
     */
    public function hasMetaData()

This method, as implied, simply checks if the content item has any meta data and returns a boolean to indicate so.

    /**
     * Fetch Meta Data
     *
     * @return    array
     * @throws    \BadMethodCallException
     */
    public function getMeta()

The getData() method fetches all meta data for a content item, returning an array that with keys indexed by the extension. If your application myapp implements a MetaData extension called CustomSomething, then you can fetch the meta data stored for an individual content item via $item->getData()['myapp_CustomSomething']

Note that meta data is stored in the core_content_meta database table.

    /**
     * Add Meta Data
     *
     * @param    string    The type of data
     * @param    array    The data
     * @return    in
     * @throws    \BadMethodCallException
     */
    public function addMeta( $type, $data )

Use the addMeta() method to store new meta data for a content item.

    /**
     * Edit Meta Data
     *
     * @param    int        The ID
     * @param    array    The data
     * @return    void
     * @throws \BadMethodCallException
     */
    public function editMeta( $id, $data )

And use the editMeta() method to update meta data for your content item records.

    /**
     * Delete Meta Data
     *
     * @param    int    The ID
     * @return    void
     */
    public function deleteMeta( $id )

The deleteMeta() method deletes meta data associated with a content item.

 

It is important to highlight that because you are adding new content item functionality when you add new MetaData extensions, you will be required to perform additional changes beyond simply adding the extension. For example, if you were adding a MetaData extension that allowed moderators to add custom moderators to a content item, you would need to perform at least the following:

  • Add links in the various associated HTML templates to add and remove the moderators (for users who have permission to do so)
  • Add controller methods that will be called to perform these actions
  • Add methods to the content item models to actually save the meta data changes using the helper methods outlined above
  • And so on..

 


  Report Document


×
×
  • Create New...