示例#1
0
 /**
  * Render the html for the input screen.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca') {
         return;
     }
     $environment = $event->getEnvironment();
     $translator = $environment->getTranslator();
     $model = $event->getModel();
     if (!$model->getProperty('isdefault')) {
         return;
     }
     $event->setArgs(array_merge($event->getArgs(), array($translator->translate('MSC.fallback'))))->setLabel(sprintf('%s <span style="color:#b3b3b3; padding-left:3px">[%%s]</span>', $event->getLabel()));
 }
示例#2
0
 /**
  * Render a model in the backend list.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') {
         return;
     }
     $model = $event->getModel();
     $translator = $event->getEnvironment()->getTranslator();
     $database = $this->getDatabase();
     if (!($model && $database->tableExists($model->getProviderName()))) {
         return;
     }
     $strLabel = vsprintf($event->getLabel(), $event->getArgs());
     $strImage = '';
     if ($model->getProperty('addImage')) {
         $arrSize = deserialize($model->getProperty('size'));
         $imageEvent = new ResizeImageEvent($model->getProperty('singleSRC'), $arrSize[0], $arrSize[1], $arrSize[2]);
         $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_RESIZE, $event);
         $strImage = sprintf('<div class="image" style="padding-top:3px"><img src="%s" alt="%%1$s" /></div> ', $imageEvent->getImage(), htmlspecialchars($strLabel));
     }
     $objCount = $database->prepare('SELECT count(*) AS itemCount FROM ' . $model->getProperty('tableName'))->execute();
     /** @noinspection PhpUndefinedFieldInspection */
     $count = $objCount->itemCount;
     $itemCount = sprintf('<span style="color:#b3b3b3; padding-left:3px">[%s]</span>', $translator->translatePluralized('itemFormatCount', $count, 'tl_metamodel', array($count)));
     $tableName = '<span style="color:#b3b3b3; padding-left:3px">(' . $model->getProperty('tableName') . ')</span>';
     $event->setArgs(array('<span class="name">' . $strLabel . $tableName . $itemCount . '</span>' . $strImage));
 }
 /**
  * Retrieve the arguments for the callback.
  *
  * @param ModelToLabelEvent $event The event being emitted.
  *
  * @return array
  */
 public function getArgs($event)
 {
     return array($event->getModel()->getPropertiesAsArray(), $event->getLabel(), new DcCompat($event->getEnvironment(), $event->getModel()), $event->getArgs());
 }