Zend_Gdata_Youtube and disallowing commenting/embedding of video

Even in the latest ZF stable release 1.11.4 there is still no support of new Youtube API accessControl element. The framework is still using yt:noembed option and has no support for disallowing commenting at all. As I tried yt:noembed – it wasn’t working, so we need to add support to ZF of this feature. First we need to understand how Youtube feed needs to be formed in order to prevent commenting and/or embedding. It’s done using element and its options.


Since ZF Gdata API has support of noembed option it has the class and methods forming RSS DOM that check for noembed element and append it where necessary, but there is no nocomment support, so we need the same extension class + DOM append this element. So first let’s create Extension_NoComment class similar to other extension classes:

I skipped long phpDoc comments, but you’d rather use them. As you see we added protected element and described its attributes for yt:accessControl (no comment option). Since it extends Zend_Gdata_Extension it will be serialized to xml string when necessary. Now we need either hack the NoEmbed extension class in the framework or create our own (same story as with NoComment) and extend if from Extension. Actually, you’d better create your own classes in your project structure and extend them from ZF classes than hack the framework itself even though it uses deprecated API version. That’s just a good practice so you can see where your code is and where ZF code is. So you’ll end up with something like:

pretty much the same as NoComment one. Now as there was no NoComment extension we should find the right place to append it to DOM. This can be done by extending VideoEntry class with your own one, overriding getDom() and adding several methods for NoComment feature:

As you see we call parent method + append our own NoComment xml.

That’s all. It should be working. Here is the test code which really works on 1.11.4:

Attached is the code of all three files explained above

Leave a Reply

Your email address will not be published. Required fields are marked *