Pull file attribute from page for add on

Permalink
Hi

I've been using the HTML5 Audio add on and want to develop it's use by putting it directly on to a page template and to then override the add on controller so that it pulls an audio file directly from the page it is on. The audio file attribute on the page is called talk_audio. The controller code for the add on is:

<?php 
namespace Concrete\Package\Html5AudioPlayerBasic\Block\Html5AudioPlayerBasic;
use Concrete\Core\Block\BlockController;
use File;
use Loader;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends BlockController
{
    protected $btTable = "btHtml5AudioPlayerBasic";
    protected $btInterfaceWidth = "600";
    protected $btInterfaceHeight = "500";
    protected $btCacheBlockRecord = true;
    protected $btCacheBlockOutput = true;
    protected $btCacheBlockOutputOnPost = true;
    protected $btCacheBlockOutputForRegisteredUsers = false;


Any help appreciated.

View Replies: View Best Answer
hutman replied on at Permalink Best Answer Reply
hutman
In the view function you should just be able replace

$f = File::getByID(intval($this->fID));

with
$c = Page::getCurrentPage();
$f = $c->getAttribute('talk_audio');
if(!is_object($f)){
   $f = File::getByID(intval($this->fID));
}

And that will get the attribute from the page, if the attribute isn't set then it will get the one from the block.
justynpride replied on at Permalink Reply
Hi

Thanks for your help. I replaced the code and then added to my page type output. When I add that page to my site I encounter the follow error:

Class 'Concrete\Package\Html5AudioPlayerBasic\Block\Html5AudioPlayerBasic\Page' not found

I can confirm that there is an audio file on the page and that the file handle is the same as in the controller:

public function view()
    {
$c = Page::getCurrentPage();
$f = $c->getAttribute('talk_audio');
if(!is_object($f)){
   $f = File::getByID(intval($this->fID));
}
      $fallback = File::getByID(intval($this->secondaryfID));
      $fileInfo = $this->getFileInfo($f, $fallback);
      if ($this->titleSource == 'DESCRIPTION') {
         $fileInfo['title'] = $fileInfo['description'];
      } elseif ($this->titleSource == 'CUSTOM') {
         $fileInfo['title'] = $this->title;
      }
      $options = array (
hutman replied on at Permalink Reply
hutman
You need to add use Page; to the top of the controller.
justynpride replied on at Permalink Reply
Spot on. Thank you SO much.