Hello,
I’m trying to build my own Extension like the ones provided in tree.
My goal is to show inside Atom xml events so this is an example I will add more tags:
- start datetime
- finish datetime
- availablity
- thumbnail and big picture
- address information
With this code and I’m able to register it:
$extensionManager = \Laminas\Feed\Writer\Writer::getExtensionManager();
$extensionManager->add('MyExtension\Renderer\Entry', \MyExtension\Renderer\Entry::class);
Laminas\Feed\Writer\Writer::registerExtension('MyExtension');
This is my class:
<?php
namespace MyExtension\Renderer;
use DOMDocument;
use DOMElement;
use Laminas\Feed\Writer\Extension;
/**
*/
class Entry extends Extension\AbstractRenderer
{
/**
* Set to TRUE if a rendering method actually renders something. This
* is used to prevent premature appending of a XML namespace declaration
* until an element which requires it is actually appended.
*
* @var bool
*/
protected $called = false;
/**
* Render entry
*
* @return void
*/
public function render()
{
if (strtolower($this->getType()) === 'rss') {
return; // Atom 1.0 only
}
$this->_setImageLink($this->dom, $this->base);
if ($this->called) {
$this->_appendNamespaces();
}
}
/**
* Append namespaces to entry root
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _appendNamespaces()
{
// @codingStandardsIgnoreEnd
$this->getRootElement()->setAttribute(
'xmlns:solg',
'http://example.it/atom/1.0'
);
}
/**
* Set image link
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
// @codingStandardsIgnoreStart
protected function _setImageLink(DOMDocument $dom, DOMElement $root)
{
// @codingStandardsIgnoreEnd
$link = $this->getDataContainer()->getImageLink();
if (! $link) {
return;
}
$clink = $this->dom->createElement('image_link');
// $clink->setAttribute('rel', 'replies');
// $clink->setAttribute('type', 'text/html');
$clink->setAttribute('href', $link);
// $count = $this->getDataContainer()->getCommentCount();
// if ($count !== null) {
// $clink->setAttribute('thr:count', $count);
// }
$root->appendChild($clink);
$this->called = true;
}
}
?>
Unluckily it breaks on render:
[Fri Mar 06 17:14:45.214753 2020] [php7:notice] [pid 28374] [client 127.0.0.1:36146] PHP Fatal error: Uncaught Laminas\\Feed\\Writer\\Exception\\BadMethodCallException: Method: getImageLink does not exist and could not be located on a registered Extension in /home/francesco/eclipse-workspace/project/vendor/laminas/laminas-feed/src/Writer/Entry.php:724
Stack trace:
#0 /home/francesco/eclipse-workspace/project/MyExtension/Renderer/Entry.php(70): Laminas\\Feed\\Writer\\Entry->__call('getImageLink', Array)
#1 /home/francesco/eclipse-workspace/project/MyExtension/Renderer/Entry.php(38): MyExtension\\Renderer\\Entry->_setImageLink(Object(DOMDocument), Object(DOMElement))
#2 /home/francesco/eclipse-workspace/project/vendor/laminas/laminas-feed/src/Writer/Renderer/Entry/Atom.php(59): MyExtension\\Renderer\\Entry->render()
#3 /home/francesco/eclipse-workspace/project/vendor/laminas/laminas-feed/src/Writer/Renderer/Feed/Atom.php(90): Laminas\\Feed\\Writer\\Renderer\\Entry\\Atom->render()
#4 /home/francesco/eclipse-workspace/project/vendor/laminas/laminas-feed/src/Writer/Feed.php(237): Laminas\\Feed\\Writer\\Renderer\\Feed\\Atom-> in /home/francesco/eclipse-workspace/project/vendor/laminas/laminas-feed/src/Writer/Entry.php on line 724
I’m not sure how to set the new property and how make it run without breaking on:
$feed->export('atom');
Any suggestion is welcome.
Many thanks
Cheers
Francesco