Skip to content

Commit

Permalink
Updated docs for Videos 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamindavid committed Mar 27, 2022
1 parent 9c46390 commit adf4906
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 24,252 deletions.
16 changes: 12 additions & 4 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,31 @@ module.exports = {
'',
'requirements',
'installation',
'updating',
]
},
{
title: 'Configuration',
collapsable: false,
children: [
'connect-youtube',
'connect-vimeo',
'configuration',
]
},
{
title: 'Core Concepts',
title: 'Usage',
collapsable: false,
children: [
'video-model',
'video-field',
'template-variables',
]
},
{
title: 'Fields',
title: 'Models',
collapsable: false,
children: [
'video-field',
'video-model',
]
},
],
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration
# Config Settings

The default plugin settings [can be overridden](https://craftcms.com/docs/3.x/extend/plugin-settings.html#overriding-setting-values) by creating a `videos.php` file under your `/config` directory.

Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Requirements

## Craft CMS
Videos requires Craft CMS 3.5.0 and above.
Videos requires Craft CMS 3.5.0 or later.

## PHP
Videos requires PHP 7.0 and above.
Videos requires PHP 7.2.5 or later.
49 changes: 49 additions & 0 deletions docs/template-variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Template Variables

## craft.videos.getEmbed(videoUrl, embedOptions = [])

Returns the embed code for a video.

- `videoUrl`: The URL of the video to embed. (Required)
- `embedOptions`: An array of options to pass to the embed.

```twig
{% set videoEmbed = craft.videos.getEmbed('https://www.youtube.com/watch?v=-Oox2w5sMcA', ['width' => '100%']) %}
{{ videoEmbed }}
```

## craft.videos.getVideoByUrl(videoUrl, enableCache = true, cacheExpiry = 3600)

Retrieve a video from its URL.

- `videoUrl`: The URL of the video to embed. (Required)
- `enableCache`: Whether to enable caching. (Default: true)
- `cacheExpiry`: The number of seconds to cache the video. (Default: 3600)

```twig
{% set video = craft.videos.getVideoByUrl('https://www.youtube.com/watch?v=-Oox2w5sMcA') %}
{% if video %}
{% if not video.hasErrors('url') %}
<ul>
<li>title: {{ video.title }}</li>
<li>url: {{ video.url }}</li>
<li>embed: {{ video.embed({ width: 300, height: 200 }) }}</li>
</ul>
{% else %}
<p>Video has errors:</p>
<ul>
{% for error in video.getErrors('url') %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<p>No video.</p>
{% endinf %}
```

## craft.videos.url(videoUrl, enableCache = true, cacheExpiry = 3600)

Alias for [craft.videos.getVideoByUrl()](#craft-videos-getvideobyurl-videourl-enablecache-true-cacheexpiry-3600).
96 changes: 96 additions & 0 deletions docs/updating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Updating Instructions

Videos may be updated like any other update to Craft or its plugins.

## Updating from the Control Panel

When an update is available, users with permission to update Craft will see a badge in the control panel next to **Utilities** in the main navigation.

From **Utilities → Updates**, any available Videos updates will be listed along with those for Craft and other plugins. Choose “Videos” to view the release notes before updating.

Always check the release notes for any changes that may impact your site. Any critical changes will be clearly identified at the top.

You can then choose the **Update** button next to Videos to update the plugin, or **Update All** to run all available plugin updates.

## Updating from the Terminal

The [`update` console command](https://craftcms.com/docs/3.x/console-commands.html#update) can be used to update Craft and plugins including Videos.

To see available updates, go to your Craft project in your terminal and run this command:

```bash
php craft update
```

If a Videos update is available, run this command to apply it:

```bash
php craft update videos
```

To update to a specific version of Videos, run this command:

```bash
php craft update videos:2.1.0
```

## Updating from Videos 2.0 to 2.1

The Videos 2.1 introduced some breaking changes.
If you’re upgrading from 2.0, you’ll need to update your templates to reflect these changes.

### Video model

If there are errors when trying to retrieve the video, they are now attached to the video model, on the URL attribute:

```twig
{% if video.hasErrors('url') %}
<p>Video has errors:</p>
<ul>
{% for error in video.getErrors('url') %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
```

### Video field

Before:

```twig
{% set video = entry.video %}
{% if video %}
<ul>
<li>title: {{ video.title }}</li>
<li>url: {{ video.url }}</li>
<li>embed: {{ video.embed({ width: 300, height: 200 }) }}</li>
</ul>
{% endinf %}
```

After:

```twig
{% set video = entry.video %}
{% if video %}
{% if not video.hasErrors('url') %}
<ul>
<li>title: {{ video.title }}</li>
<li>url: {{ video.url }}</li>
<li>embed: {{ video.embed({ width: 300, height: 200 }) }}</li>
</ul>
{% else %}
<p>Video has errors:</p>
<ul>
{% for error in video.getErrors('url') %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<p>No video.</p>
{% endinf %}
```
23 changes: 18 additions & 5 deletions docs/video-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ The Video field returns a [Video model](video-model.md) which you can use to acc
```twig
{% set video = entry.video %}
<ul>
<li>title: {{ video.title }}</li>
<li>url: {{ video.url }}</li>
<li>embed: {{ video.embed({ width: 300, height: 200 }) }}</li>
</ul>
{% if video %}
{% if not video.hasErrors('url') %}
<ul>
<li>title: {{ video.title }}</li>
<li>url: {{ video.url }}</li>
<li>embed: {{ video.embed({ width: 300, height: 200 }) }}</li>
</ul>
{% else %}
<p>Video has errors:</p>
<ul>
{% for error in video.getErrors('url') %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<p>No video.</p>
{% endinf %}
```
Loading

0 comments on commit adf4906

Please sign in to comment.