84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace RomhackPlaza\Extenders\Timber;
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
use Timber;
|
|
use Twig\Compiler;
|
|
use Twig\Token;
|
|
use Twig\Node\Node;
|
|
|
|
class SubmissionAccordionNode extends Node {
|
|
|
|
public static function get_sapretty_title( string $type_name ){
|
|
|
|
switch( $type_name ){
|
|
case 'download-files':
|
|
return __('Download Files', 'romhackplaza');
|
|
break;
|
|
case 'about-translation':
|
|
return __('About the Patch', 'romhackplaza');
|
|
break;
|
|
case 'game-information':
|
|
return __('Game Information', 'romhackplaza');
|
|
break;
|
|
case 'attachments':
|
|
return __('Attachments', 'romhackplaza');
|
|
break;
|
|
case 'team-information':
|
|
return __('Team Information', 'romhackplaza');
|
|
break;
|
|
}
|
|
|
|
return __( "Unknown", 'romhackplaza' );
|
|
}
|
|
|
|
public static function get_safa_icon( mixed $type_name){
|
|
|
|
switch( $type_name ){
|
|
case 'download-files':
|
|
return 'fas fa-download';
|
|
break;
|
|
case 'about-translation':
|
|
return 'fas fa-language';
|
|
break;
|
|
case 'game-information':
|
|
return 'fas fa-gamepad';
|
|
break;
|
|
case 'attachments':
|
|
return 'fas fa-paperclip';
|
|
break;
|
|
case 'team-information':
|
|
return 'fas fa-users';
|
|
break;
|
|
}
|
|
|
|
return 'fas fa-question-circle';
|
|
|
|
}
|
|
|
|
public function compile( Compiler $compiler ) {
|
|
|
|
$compiler->addDebugInfo($this)
|
|
->write( "ob_start();\n" )
|
|
->subcompile( $this->getNode('body') )
|
|
->write("\$content = ob_get_clean();\n")
|
|
->write("\$type = ")
|
|
->subcompile( $this->getNode('type') )
|
|
->raw(";\n")
|
|
->write("\$icon = \RomhackPlaza\Extenders\Timber\SubmissionAccordionNode::get_safa_icon( \$type );\n")
|
|
->write("\$pretty_title = \RomhackPlaza\Extenders\Timber\SubmissionAccordionNode::get_sapretty_title( \$type );\n")
|
|
->write("\$opened = \$context['accordion_opened'] ?? false;\n")
|
|
->write("echo Timber::compile('@plugin/node/submission-accordion.twig', [\n")
|
|
->indent()
|
|
->write("'type' => \$type,\n")
|
|
->write("'content' => \$content,\n")
|
|
->write("'pretty_title' => \$pretty_title,\n")
|
|
->write("'icon' => \$icon,\n")
|
|
->write("'accordion_opened' => \$opened,\n")
|
|
->outdent()
|
|
->write("]);\n");
|
|
;
|
|
}
|
|
|
|
} |