├── .gitignore ├── LICENSE ├── README.md ├── autoloads └── eztemplateautoload.php ├── classes ├── ngsymfonytoolsapicontentconverter.php ├── ngsymfonytoolscontrolleroperator.php ├── ngsymfonytoolsincludeoperator.php ├── ngsymfonytoolsisgrantedoperator.php ├── ngsymfonytoolspathurloperator.php └── ngsymfonytoolsrenderoperator.php ├── composer.json ├── doc ├── INSTALL.md └── USAGE.md ├── extension.xml ├── ezinfo.php └── settings └── site.ini.append.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) 19yy name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Netgen Symfony Tools 2 | 3 | [![Downloads](https://img.shields.io/packagist/dt/netgen/ngsymfonytools.svg?style=flat-square)](https://packagist.org/packages/netgen/ngsymfonytools/stats) 4 | [![Latest stable](https://img.shields.io/packagist/v/netgen/ngsymfonytools.svg?style=flat-square)](https://packagist.org/packages/netgen/ngsymfonytools) 5 | [![License](https://img.shields.io/github/license/netgen/ngsymfonytools.svg?style=flat-square)](LICENSE) 6 | [![PHP](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://secure.php.net/) 7 | 8 | Netgen Symfony Tools is an eZ Publish 4 extension that provides a way to include Twig templates, as well as running Symfony sub-requests, directly from the eZ Publish legacy templates. 9 | 10 | This extension is published under GNU GPLv2 license and as such can be freely used and modified. 11 | 12 | ## License, installation instructions and usage examples 13 | 14 | [License](LICENSE) 15 | 16 | [Installation instructions](doc/INSTALL.md) 17 | 18 | [Usage](doc/USAGE.md) 19 | 20 | ## Project page 21 | 22 | You can find the project page on [projects.ez.no](http://projects.ez.no/ngsymfonytools) 23 | -------------------------------------------------------------------------------- /autoloads/eztemplateautoload.php: -------------------------------------------------------------------------------- 1 | 'NgSymfonyToolsIncludeOperator', 7 | 'operator_names' => array( 'symfony_include' ) 8 | ); 9 | 10 | $eZTemplateOperatorArray[] = array( 11 | 'class' => 'NgSymfonyToolsRenderOperator', 12 | 'operator_names' => array( 'symfony_render', 'symfony_render_esi', 'symfony_render_hinclude' ) 13 | ); 14 | 15 | $eZTemplateOperatorArray[] = array( 16 | 'class' => 'NgSymfonyToolsControllerOperator', 17 | 'operator_names' => array( 'symfony_controller' ) 18 | ); 19 | 20 | $eZTemplateOperatorArray[] = array( 21 | 'class' => 'NgSymfonyToolsPathUrlOperator', 22 | 'operator_names' => array( 'symfony_path', 'symfony_url' ) 23 | ); 24 | 25 | $eZTemplateOperatorArray[] = array( 26 | 'class' => 'NgSymfonyToolsIsGrantedOperator', 27 | 'operator_names' => array( 'symfony_is_granted' ) 28 | ); 29 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolsapicontentconverter.php: -------------------------------------------------------------------------------- 1 | getServiceContainer(); 27 | self::$instance = new self( $serviceContainer->get( 'ezpublish.api.repository' ) ); 28 | } 29 | 30 | return self::$instance; 31 | } 32 | 33 | /** 34 | * Constructor 35 | * 36 | * @private 37 | * 38 | * @param \eZ\Publish\API\Repository\Repository $repository 39 | */ 40 | private function __construct( Repository $repository ) 41 | { 42 | $this->repository = $repository; 43 | } 44 | 45 | /** 46 | * Disallows cloning 47 | */ 48 | private function __clone() 49 | { 50 | } 51 | 52 | /** 53 | * Converts eZ Publish legacy objects and nodes to content and locations 54 | * 55 | * @param mixed $object 56 | * 57 | * @return mixed 58 | */ 59 | public function convert( $object ) 60 | { 61 | if ( $object instanceof eZContentObject ) 62 | { 63 | return $this->repository->getContentService()->loadContent( $object->attribute( 'id' ) ); 64 | } 65 | else if ( $object instanceof eZContentObjectTreeNode ) 66 | { 67 | return $this->repository->getLocationService()->loadLocation( $object->attribute( 'node_id' ) ); 68 | } 69 | 70 | return $object; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolscontrolleroperator.php: -------------------------------------------------------------------------------- 1 | array( 36 | 'controller' => array( 37 | 'type' => 'string', 38 | 'required' => true 39 | ), 40 | 'attributes' => array( 41 | 'type' => 'array', 42 | 'required' => false, 43 | 'default' => array() 44 | ), 45 | 'query' => array( 46 | 'type' => 'array', 47 | 'required' => false, 48 | 'default' => array() 49 | ) 50 | ) 51 | ); 52 | } 53 | 54 | /** 55 | * Executes the template operator 56 | * 57 | * @param eZTemplate $tpl 58 | * @param string $operatorName 59 | * @param mixed $operatorParameters 60 | * @param string $rootNamespace 61 | * @param string $currentNamespace 62 | * @param mixed $operatorValue 63 | * @param array $namedParameters 64 | * @param mixed $placement 65 | */ 66 | function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 67 | { 68 | if ( !is_string( $namedParameters['controller'] ) || empty( $namedParameters['controller'] ) ) 69 | { 70 | $tpl->error( $operatorName, "$operatorName parameter 'controller' must be a non empty string.", $placement ); 71 | return; 72 | } 73 | 74 | $controller = $namedParameters['controller']; 75 | 76 | if ( $namedParameters['attributes'] !== null && !is_array( $namedParameters['attributes'] ) ) 77 | { 78 | $tpl->error( $operatorName, "$operatorName parameter 'attributes' must be a hash array.", $placement ); 79 | return; 80 | } 81 | 82 | $attributes = $namedParameters['attributes'] !== null ? $namedParameters['attributes'] : array(); 83 | 84 | if ( $namedParameters['query'] !== null && !is_array( $namedParameters['query'] ) ) 85 | { 86 | $tpl->error( $operatorName, "$operatorName parameter 'query' must be a hash array.", $placement ); 87 | return; 88 | } 89 | 90 | $query = $namedParameters['query'] !== null ? $namedParameters['query'] : array(); 91 | 92 | $apiContentConverter = NgSymfonyToolsApiContentConverter::instance(); 93 | foreach ( $attributes as $attributeName => $attributeValue ) 94 | { 95 | $attributes[$attributeName] = $apiContentConverter->convert( $attributeValue ); 96 | } 97 | 98 | $operatorValue = self::getController( $controller, $attributes, $query ); 99 | } 100 | 101 | /** 102 | * Returns the controller reference for the specified controller name 103 | * 104 | * @param string $controller 105 | * @param array $attributes 106 | * @param array $query 107 | * 108 | * @return \Symfony\Component\HttpKernel\Controller\ControllerReference 109 | */ 110 | public static function getController( $controller, $attributes = array(), $query = array() ) 111 | { 112 | return new ControllerReference( $controller, $attributes, $query ); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolsincludeoperator.php: -------------------------------------------------------------------------------- 1 | array( 34 | 'name' => array( 35 | 'type' => 'string', 36 | 'required' => true 37 | ), 38 | 'parameters' => array( 39 | 'type' => 'array', 40 | 'required' => false, 41 | 'default' => array() 42 | ) 43 | ) 44 | ); 45 | } 46 | 47 | /** 48 | * Executes the template operator 49 | * 50 | * @param eZTemplate $tpl 51 | * @param string $operatorName 52 | * @param mixed $operatorParameters 53 | * @param string $rootNamespace 54 | * @param string $currentNamespace 55 | * @param mixed $operatorValue 56 | * @param array $namedParameters 57 | * @param mixed $placement 58 | */ 59 | function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 60 | { 61 | if ( !is_string( $namedParameters['name'] ) || empty( $namedParameters['name'] ) ) 62 | { 63 | $tpl->error( $operatorName, "$operatorName parameter 'name' must be a non empty string.", $placement ); 64 | return; 65 | } 66 | 67 | $templateName = $namedParameters['name']; 68 | 69 | if ( $namedParameters['parameters'] !== null && !is_array( $namedParameters['parameters'] ) ) 70 | { 71 | $tpl->error( $operatorName, "$operatorName parameter 'parameters' must be a hash array.", $placement ); 72 | return; 73 | } 74 | 75 | $templateParameters = $namedParameters['parameters'] !== null ? $namedParameters['parameters'] : array(); 76 | 77 | $apiContentConverter = NgSymfonyToolsApiContentConverter::instance(); 78 | foreach ( $templateParameters as $parameterName => $parameterValue ) 79 | { 80 | $templateParameters[$parameterName] = $apiContentConverter->convert( $parameterValue ); 81 | } 82 | 83 | $serviceContainer = ezpKernel::instance()->getServiceContainer(); 84 | $templatingEngine = $serviceContainer->get( 'templating' ); 85 | $operatorValue = $templatingEngine->render( $templateName, $templateParameters ); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolsisgrantedoperator.php: -------------------------------------------------------------------------------- 1 | array( 37 | 'role' => array( 38 | 'required' => true 39 | ), 40 | 'object' => array( 41 | 'required' => false, 42 | 'default' => null 43 | ), 44 | 'field' => array( 45 | 'required' => false, 46 | 'default' => null 47 | ) 48 | ) 49 | ); 50 | } 51 | 52 | /** 53 | * Executes the template operator 54 | * 55 | * @param eZTemplate $tpl 56 | * @param string $operatorName 57 | * @param mixed $operatorParameters 58 | * @param string $rootNamespace 59 | * @param string $currentNamespace 60 | * @param mixed $operatorValue 61 | * @param array $namedParameters 62 | * @param mixed $placement 63 | */ 64 | function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 65 | { 66 | $role = $namedParameters['role']; 67 | $object = isset( $namedParameters['object'] ) ? $namedParameters['object'] : null; 68 | $field = isset( $namedParameters['field'] ) ? $namedParameters['field'] : null; 69 | 70 | $operatorValue = self::isGranted( $role, $object, $field ); 71 | } 72 | 73 | /** 74 | * Returns if the current user has access to provided role. 75 | * 76 | * @param mixed $role 77 | * @param mixed $object 78 | * @param mixed $field 79 | * 80 | * @return bool 81 | */ 82 | public static function isGranted( $role, $object = null, $field = null ) 83 | { 84 | $serviceContainer = ezpKernel::instance()->getServiceContainer(); 85 | 86 | if ( $field !== null && class_exists( 'Symfony\Component\Security\Acl\Voter\FieldVote' ) ) 87 | { 88 | $object = new FieldVote( $object, $field ); 89 | } 90 | 91 | try 92 | { 93 | return $serviceContainer->get( 'security.authorization_checker' )->isGranted( $role, $object ); 94 | } 95 | catch ( AuthenticationCredentialsNotFoundException $e ) 96 | { 97 | return false; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolspathurloperator.php: -------------------------------------------------------------------------------- 1 | array( 36 | 'name' => array( 37 | 'type' => 'string', 38 | 'required' => true 39 | ), 40 | 'parameters' => array( 41 | 'type' => 'array', 42 | 'required' => false, 43 | 'default' => array() 44 | ), 45 | 'relative' => array( 46 | 'type' => 'boolean', 47 | 'required' => false, 48 | 'default' => false 49 | ) 50 | ), 51 | 'symfony_url' => array( 52 | 'name' => array( 53 | 'type' => 'string', 54 | 'required' => true 55 | ), 56 | 'parameters' => array( 57 | 'type' => 'array', 58 | 'required' => false, 59 | 'default' => array() 60 | ), 61 | 'scheme_relative' => array( 62 | 'type' => 'boolean', 63 | 'required' => false, 64 | 'default' => false 65 | ) 66 | ) 67 | ); 68 | } 69 | 70 | /** 71 | * Executes the template operator 72 | * 73 | * @param eZTemplate $tpl 74 | * @param string $operatorName 75 | * @param mixed $operatorParameters 76 | * @param string $rootNamespace 77 | * @param string $currentNamespace 78 | * @param mixed $operatorValue 79 | * @param array $namedParameters 80 | * @param mixed $placement 81 | */ 82 | function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 83 | { 84 | if ( !is_string( $namedParameters['name'] ) || empty( $namedParameters['name'] ) ) 85 | { 86 | $tpl->error( $operatorName, "$operatorName parameter 'name' must be a non empty string.", $placement ); 87 | return; 88 | } 89 | 90 | $name = $namedParameters['name']; 91 | 92 | if ( $namedParameters['parameters'] !== null && !is_array( $namedParameters['parameters'] ) ) 93 | { 94 | $tpl->error( $operatorName, "$operatorName parameter 'parameters' must be a hash array.", $placement ); 95 | return; 96 | } 97 | 98 | $parameters = $namedParameters['parameters'] !== null ? $namedParameters['parameters'] : array(); 99 | 100 | if ( $operatorName === 'symfony_path' ) 101 | { 102 | $relative = isset( $namedParameters['relative'] ) && $namedParameters['relative'] === true; 103 | $operatorValue = self::getPath( $name, $parameters, $relative ); 104 | } 105 | else if ( $operatorName === 'symfony_url' ) 106 | { 107 | $schemeRelative = isset( $namedParameters['scheme_relative'] ) && $namedParameters['scheme_relative'] === true; 108 | $operatorValue = self::getUrl( $name, $parameters, $schemeRelative ); 109 | } 110 | } 111 | 112 | /** 113 | * Returns the path for provided route and parameters 114 | * 115 | * @param string $name 116 | * @param array $parameters 117 | * @param bool $relative 118 | * 119 | * @return string 120 | */ 121 | public static function getPath( $name, $parameters = array(), $relative = false ) 122 | { 123 | $serviceContainer = ezpKernel::instance()->getServiceContainer(); 124 | 125 | return $serviceContainer->get('router')->generate( 126 | $name, 127 | $parameters, 128 | $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH 129 | ); 130 | } 131 | 132 | /** 133 | * Returns the URL for provided route and parameters 134 | * 135 | * @param string $name 136 | * @param array $parameters 137 | * @param bool $schemeRelative 138 | * 139 | * @return string 140 | */ 141 | public static function getUrl( $name, $parameters = array(), $schemeRelative = false ) 142 | { 143 | $serviceContainer = ezpKernel::instance()->getServiceContainer(); 144 | 145 | return $serviceContainer->get('router')->generate( 146 | $name, 147 | $parameters, 148 | $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL 149 | ); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /classes/ngsymfonytoolsrenderoperator.php: -------------------------------------------------------------------------------- 1 | array( 36 | 'uri' => array( 37 | 'type' => 'string', 38 | 'required' => true 39 | ), 40 | 'options' => array( 41 | 'type' => 'array', 42 | 'required' => false, 43 | 'default' => array() 44 | ) 45 | ), 46 | 'symfony_render_esi' => array( 47 | 'uri' => array( 48 | 'type' => 'string', 49 | 'required' => true 50 | ), 51 | 'options' => array( 52 | 'type' => 'array', 53 | 'required' => false, 54 | 'default' => array() 55 | ) 56 | ), 57 | 'symfony_render_hinclude' => array( 58 | 'uri' => array( 59 | 'type' => 'string', 60 | 'required' => true 61 | ), 62 | 'options' => array( 63 | 'type' => 'array', 64 | 'required' => false, 65 | 'default' => array() 66 | ) 67 | ) 68 | ); 69 | } 70 | 71 | /** 72 | * Executes the template operator 73 | * 74 | * @param eZTemplate $tpl 75 | * @param string $operatorName 76 | * @param mixed $operatorParameters 77 | * @param string $rootNamespace 78 | * @param string $currentNamespace 79 | * @param mixed $operatorValue 80 | * @param array $namedParameters 81 | * @param mixed $placement 82 | */ 83 | function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 84 | { 85 | if ( !$namedParameters['uri'] instanceof ControllerReference && 86 | !( is_string( $namedParameters['uri'] ) && !empty( $namedParameters['uri'] ) ) ) 87 | { 88 | $tpl->error( $operatorName, "$operatorName parameter 'uri' must be a non empty string or a controller reference.", $placement ); 89 | return; 90 | } 91 | 92 | $uri = $namedParameters['uri']; 93 | 94 | if ( $namedParameters['options'] !== null && !is_array( $namedParameters['options'] ) ) 95 | { 96 | $tpl->error( $operatorName, "$operatorName parameter 'options' must be a hash array.", $placement ); 97 | return; 98 | } 99 | 100 | $options = $namedParameters['options'] !== null ? $namedParameters['options'] : array(); 101 | 102 | if ( $operatorName === 'symfony_render_esi' ) 103 | { 104 | $options['strategy'] = 'esi'; 105 | } 106 | else if ( $operatorName === 'symfony_render_hinclude' ) 107 | { 108 | $options['strategy'] = 'hinclude'; 109 | } 110 | 111 | $operatorValue = self::renderUri( $uri, $options ); 112 | } 113 | 114 | /** 115 | * Renders the given URI with Symfony stack 116 | * 117 | * @param string|\Symfony\Component\HttpKernel\Controller\ControllerReference $uri 118 | * @param array $options 119 | * 120 | * @return string 121 | */ 122 | public static function renderUri( $uri, $options = array() ) 123 | { 124 | $serviceContainer = ezpKernel::instance()->getServiceContainer(); 125 | $fragmentHandler = $serviceContainer->get( 'fragment.handler' ); 126 | 127 | $strategy = isset( $options['strategy'] ) ? $options['strategy'] : 'inline'; 128 | unset( $options['strategy'] ); 129 | 130 | try 131 | { 132 | return $fragmentHandler->render( $uri, $strategy, $options ); 133 | } 134 | catch ( InvalidArgumentException $e ) 135 | { 136 | throw new InvalidArgumentException( "The URI {$uri->controller} couldn't be rendered", 0, $e ); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netgen/ngsymfonytools", 3 | "description": "Netgen Symfony Tools is an eZ Publish 4 extension that provides a way to include Twig templates, as well as running Symfony sub-requests, directly from the eZ Publish legacy templates.", 4 | "type": "ezpublish-legacy-extension", 5 | "license": "GPL-2.0-only", 6 | "authors": [ 7 | { 8 | "name": "Netgen", 9 | "email": "info@netgen.hr" 10 | } 11 | ], 12 | "require": { 13 | "ezsystems/ezpublish-legacy-installer": "*" 14 | }, 15 | "extra": { 16 | "ezpublish-legacy-extension-name": "ngsymfonytools" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /doc/INSTALL.md: -------------------------------------------------------------------------------- 1 | # Netgen Symfony Tools extension installation instructions 2 | 3 | ## Requirements 4 | 5 | * eZ Publish 5.1+ running with Symfony stack 6 | 7 | ## Installation 8 | 9 | ### Install through Composer 10 | 11 | eZ Publish already comes bundled with the extension, so you can ofcourse skip this step if your 12 | installation already has the extension. Otherwise, you can install the extension with the 13 | following command: 14 | 15 | php composer.phar require netgen/ngsymfonytools:~1.1 16 | 17 | ### Activate extension 18 | 19 | Activate the extension by using the admin interface ( Setup -> Extensions ) or by 20 | prepending `ngsymfonytools` to `ActiveExtensions[]` in `ezpublish_legacy/settings/override/site.ini.append.php`: 21 | 22 | ```ini 23 | [ExtensionSettings] 24 | ActiveExtensions[]=ngsymfonytools 25 | ``` 26 | 27 | ### Regenerate the legacy autoload array 28 | 29 | Run the following from your installation root folder 30 | 31 | php ezpublish/console ezpublish:legacy:script bin/php/ezpgenerateautoloads.php 32 | 33 | Or go to Setup -> Extensions in admin interface and click the "Regenerate autoload arrays" button 34 | -------------------------------------------------------------------------------- /doc/USAGE.md: -------------------------------------------------------------------------------- 1 | # Netgen Symfony Tools template usage examples 2 | 3 | ## Template operators 4 | 5 | ### `symfony_include` 6 | 7 | `symfony_include` template operator enables you to include a Twig template (or any kind of template available to Symfony) from your eZ Publish legacy template. 8 | 9 | You need to specify the template name and list of parameters that will be transferred to the included template. 10 | 11 | If any of your parameters are instances of `eZContentObject` or `eZContentObjectTreeNode`, they will be converted to instances of `\eZ\Publish\API\Repository\Values\Content\Content` and `\eZ\Publish\API\Repository\Values\Content\Location` respectivelly, before being passed to the included template. 12 | 13 | Example call: 14 | 15 | ```smarty 16 | {symfony_include( 17 | 'NetgenTestBundle:Test:test.html.twig', 18 | hash( 19 | 'theAnswer', 42, 20 | 'homepage', fetch( 'content', 'node', hash( 'node_id', 2 ) ) 21 | ) 22 | )} 23 | ``` 24 | 25 | ### `symfony_path` 26 | 27 | `symfony_path` template operator gets a relative URL for the given route. Parameters are the same as with Twig `path` template function so please refer to [this page][1] for documentation. 28 | 29 | This template operator can be used together with `symfony_render` template operator (see below) to refer to the route that you want to render. 30 | 31 | Example call: 32 | 33 | ```smarty 34 | {symfony_path( 35 | 'netgen_test_route', 36 | hash( 'theAnswer', 42 ) 37 | )} 38 | ``` 39 | 40 | ### `symfony_url` 41 | 42 | `symfony_url` template operator gets an absolute URL for the given route. Parameters are the same as with Twig `url` template function so please refer to [this page][1] for documentation. 43 | 44 | This template operator can be used together with `symfony_render` template operator (see below) to refer to the route that you want to render. 45 | 46 | Example call: 47 | 48 | ```smarty 49 | {symfony_url( 50 | 'netgen_test_route', 51 | hash( 'theAnswer', 42 ) 52 | )} 53 | ``` 54 | 55 | ### `symfony_controller` 56 | 57 | `symfony_controller` template operator is not useful by itself. It is used together with `symfony_render` template operator (see below) to refer to the controller that you want to render. Parameters are the same as with Twig `controller` template function so please refer to [this page][1] for documentation. 58 | 59 | If any of your parameters are instances of `eZContentObject` or `eZContentObjectTreeNode`, they will be converted to instances of `\eZ\Publish\API\Repository\Values\Content\Content` and `\eZ\Publish\API\Repository\Values\Content\Location` respectivelly, before being passed to the controller. 60 | 61 | Example call: 62 | 63 | ```smarty 64 | {symfony_controller( 65 | 'NetgenTestBundle:Test:test', 66 | hash( 67 | 'theAnswer', 42, 68 | 'homepage', fetch( 'content', 'node', hash( 'node_id', 2 ) ) 69 | ), 70 | hash( 71 | 'queryParam1', 'netgen', 72 | 'queryParam2', 'symfony' 73 | ) 74 | )} 75 | ``` 76 | 77 | ### `symfony_render` 78 | 79 | `symfony_render` template operator is a big one. It allows you to render a Symfony controller directly in eZ Publish legacy template. Parameters are the same as with Twig `render` template function so please refer to [this page][1] for documentation. 80 | 81 | Example calls: 82 | 83 | ```smarty 84 | {symfony_render( 85 | symfony_controller( 86 | 'NetgenTestBundle:Test:test', 87 | hash( 88 | 'theAnswer', 42, 89 | 'homepage', fetch( 'content', 'node', hash( 'node_id', 2 ) ) 90 | ) 91 | ) 92 | )} 93 | ``` 94 | 95 | ```smarty 96 | {symfony_render( 97 | symfony_path( 98 | 'netgen_test_route', 99 | hash( 'theAnswer', 42 ) 100 | ) 101 | )} 102 | ``` 103 | 104 | ```smarty 105 | {symfony_render( 106 | symfony_url( 107 | 'netgen_test_route', 108 | hash( 'theAnswer', 42 ) 109 | ) 110 | )} 111 | ``` 112 | 113 | ### `symfony_render_esi` and `symfony_render_hinclude` 114 | 115 | `symfony_render_esi` and `symfony_render_hinclude` template operators generate an ESI tag or Hinclude tag, respectivelly, for the given controller or URL. Parameters are the same as with Twig `render_esi` and `render_hinclude` template functions so please refer to [this page][1] for documentation. 116 | 117 | `symfony_render_esi` template operator can be used instead of `symfony_render` operator, because underlying `render_esi` Twig template function falls back to `render` behavior if reverse proxy is not detected by Symfony. 118 | 119 | ESI example call: 120 | 121 | ```smarty 122 | {symfony_render_esi( 123 | symfony_controller( 124 | 'NetgenTestBundle:Test:test', 125 | hash( 126 | 'theAnswer', 42, 127 | 'homepage', fetch( 'content', 'node', hash( 'node_id', 2 ) ) 128 | ) 129 | ) 130 | )} 131 | ``` 132 | 133 | Hinclude example call: 134 | 135 | ```smarty 136 | {symfony_render_hinclude( 137 | symfony_controller( 138 | 'NetgenTestBundle:Test:test', 139 | hash( 140 | 'theAnswer', 42, 141 | 'homepage', fetch( 'content', 'node', hash( 'node_id', 2 ) ) 142 | ) 143 | ) 144 | )} 145 | ``` 146 | 147 | ### `symfony_is_granted` 148 | 149 | `symfony_is_granted` template operator enables you to use Symfony's `is_granted` Twig function from your legacy template. 150 | 151 | Example call: 152 | 153 | ```smarty 154 | {set $is_admin = symfony_is_granted( 'ROLE_ADMIN' )} 155 | ``` 156 | 157 | [1]: http://symfony.com/doc/current/reference/twig_reference.html 158 | -------------------------------------------------------------------------------- /extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Netgen Symfony Tools 5 | 1.1 6 | Copyright (C) 2014 Netgen d.o.o. 7 | GNU General Public License v2.0 8 | http://projects.ez.no/ngsymfonytools 9 | 10 | 11 | -------------------------------------------------------------------------------- /ezinfo.php: -------------------------------------------------------------------------------- 1 | 'Netgen Symfony Tools extension', 9 | 'Version' => '1.1', 10 | 'Copyright' => 'Copyright (C) 2014 Netgen d.o.o.', 11 | 'License' => 'GNU General Public License v2.0' 12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /settings/site.ini.append.php: -------------------------------------------------------------------------------- 1 |