其他分享
首页 > 其他分享> > TYPO3中便捷操作

TYPO3中便捷操作

作者:互联网

以下分享的一些便捷操作可以说都是干货了,有二次开发typo3的小伙伴可以省去不少google的时间 [aru_36],这篇文章会持续更新,这段时间工作比较忙,有时间再写 [aru_147]

最方便的debug

//输出对象查询的SQL语句
$queryParser = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($queryParser->convertQueryToDoctrineQueryBuilder($query)->getSQL());
<!-- 输出变量{_all}代表所有变量 -->
<f:debug>{data}</f:debug>
<f:debug>{_all}</f:debug>

在PHP中拼接符合typo3规则的URL链接

$uParams = array(
	array(
    'tx_areas_area' = array(
        'action' = 'yourActionName',
        'controller' = 'yourControllerName',
        'plugin' = 'yourPluginName',
        'moreParams' = 其他参数
        )
    )

-参数说明:

 $uConfs = array(
     'useCacheHash' = 1,(0或1)
     'no_cache' = 0,(0或1)
     'parameter' = 168,(pageUID)
     'moreParams' = ''(其他参数)
 );
 $objUrl = $this-createTypo3LinkUrl($uParams,$uConfs);
 string 'areas/?tx_areas_area%5Baction%5D=action&tx_areas_area%5Bcontroller%5D=controller&tx_areas_area%5Bplugin%5D=plugin&tx_areas_area%5BmoreParams%5D=252&cHash=8aa773ad881f38fc0a78d7dc80bb1be4'
 /**
  * 构成typo3的链接
  * createTypo3LinkUrl
  */
 private function createTypo3LinkUrl($uParams,$uConfs){
 	$conf=array();
 	$conf['useCacheHash'] = $uConfs['useCacheHash'];
 	$conf['no_cache'] = $uConfs['no_cache'];
 	$conf['parameter'] = $uConfs['parameter'];
     $conf['additionalParams'] = GeneralUtility::implodeArrayForUrl('', $uParams, '', TRUE).$uConfs['moreParams'];
     
     $cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
     $cObj-typoLink('|', $conf);
     $url = $cObj->lastTypoLinkUrl;
 	return $url;
 }

typo3 页面跳转

$this->forward($actionName, $controllerName, $extensionName, array $arguments);
$this->redirect($actionName, $controllerName, $extensionName, array $arguments, $pageUid, $delay = 0, $statusCode = 303);
$this->redirectToURI($uri, $delay=0, $statusCode=303);
$this->throwStatus($statusCode, $statusMessage, $content);

修改typo3中通知样式

\var\www\html\domain\typo3\sysext\core\Classes\Messaging\Renderer\ListRenderer.php
  /*将函数内容全部注释,方便以后修改*/
  /**
  * Gets the message rendered as clean and secure markup
  *
  * @param FlashMessage[] $flashMessages
  * @return string
  */
  protected function getMessageAsMarkup(array $flashMessages) : string
  {
      //源代码注释掉
      /*$markup = [];
          $script = [];
          $markup[] = '<ul class="typo3-messages whbedit">';
          foreach ($flashMessages as $flashMessage) {
              $messageTitle = $flashMessage->getTitle();
              $markup[] = '<li class="alert ' . htmlspecialchars($this->getClass($flashMessage)) . '">';
              if ($messageTitle !== '') {
                  $markup[] = '<h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
              }
              $markup[] = '<p class="alert-message">' . htmlspecialchars($flashMessage->getMessage()) . '</p>';
              $markup[] = '</li>';
          }
          $markup[] = '</ul>';
          return implode('', $markup);*/

      /*王宏彬于 2018-04-11 15:43修改*/
      //重新写执行逻辑
      $markup = [];
      $markup[] = '<script>';
      $markup[] = '$(function(){';
      foreach ($flashMessages as $flashMessage) {
          $messageTitle = $flashMessage->getTitle();
          if ($messageTitle !== '') {
              # your code
          }
          $markup[] = "UIkit.notify({message:'" . htmlspecialchars($flashMessage->getMessage()) . "', status:'".htmlspecialchars($this->getClass($flashMessage))."', timeout:500, pos:'top-center'});";
      }
      $markup[] = '});';
      $markup[] = '</script>';
      return implode('', $markup);
  }

可检查上述文件中函数 getClass() 该函数中修改你的css样式class

  /**
  * Gets the message severity class name
  *
  * @param FlashMessage $flashMessage
  *
  * @return string The message severity class name
  */
  protected function getClass(FlashMessage $flashMessage) : string
  {
      /*王宏彬于 2018-04-11 15:43修改*/
      // return 'alert-' . self::$classes[$flashMessage->getSeverity()];
      return self::$classes[$flashMessage->getSeverity()];
  }

再次运行检查,效果正常的话替换成功 [aru_51]

typo3中ViewHelper的书写示例

#InListViewHelper.php
<?php
namespace GeorgRinger\Theme\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
 * typo3的辅助方法,判断目标元素存在于集合
 *
 * = Examples =
 *
 * <code title="Basic usage">
 * {theme:inList(list: '1,2', item:data.layout, then: 'someClass', else: '')}"
 * </code>
 * <output>
 * 如果当前页的字段'布局'包含在1或2,则显示字符串'someClass'。
 * </output>
 */
class InListViewHelper extends AbstractConditionViewHelper {

	/**
	 * 判断,如果目标元素存在于集合,返回 thenChild
	 * 不存在,返回 elseChild
	 *
	 * @param string $list 集合
	 * @param string $item 目标元素
	 * @return string
	 */
	public function render($list, $item) {
		if (GeneralUtility::inList($list, $item)) {
			return $this->renderThenChild();
		} else {
			return $this->renderElseChild();
		}
	}
}

在控制器中获取当前扩展信息

标签:TYPO3,typo3,return,string,便捷,markup,flashMessage,操作,array
来源: https://www.cnblogs.com/sanlilin/p/14153161.html