2017-10-19 136 views
1

我是SilverStripe报告的新手,但至今尚未找到与此特定问题相关的任何内容。SilverStripe 3.4自定义报告 - 将文件名设置为自定义报告中的链接,以便于编辑

我有一个自定义报告,列出了网站中的所有图像和文件在gridview中,但是,我想使它可以让人们点击文件名并转到图像或文件进行编辑,或者每个图像和文件都有一个编辑按钮。现在,如果有人想编辑文件或图像,他们必须离开报告,进入文件选项卡,搜索所述文件/图像,然后单击进行编辑。这很枯燥。

我知道有一种方法可以根据cms/code/reports中的现有报告示例在报告中使页面标题可点击。但是我没有看到任何与链接上传的图像和文件相关的内容。

有没有办法做到这一点?

这里是我的自定义报表代码:

<?php 

class CustomSideReport_ListofImagesAndFiles extends SS_Report { 

    // the name of the report 
    public function title() { 
     return 'All Images and Files'; 
    } 

    // what we want the report to return 
    public function sourceRecords($params = null) 
    { 
     return File::get() 
      ->sort('Title'); 
    } 

    // which fields on that object we want to show 
    public function columns() { 
     return array(
      "Title" => 'Image Title', 
      'Filename' => array(
       "Filename" => "Filename", 
       "link" => true, 
      ), 
     ); 
    } 

} 

使用"link" => true不工作 - 它试图创建一个网页链接,这是不对的。我试过了“编辑”和“CanEdit”。

回答

1

好吧,我从引用设置为断开链接想出了这个报告:

// which fields on that object we want to show 
public function columns() 
{ 
    $linkBase = singleton('CMSFileAddController')->Link('EditForm/field/File/item'); 
    $linkBaseEditLink = str_replace("/add","",$linkBase); 
    $fields = array(
     'Title' => 'Title', 
     'AbsoluteLink' => array(
      'title' => _t('CustomSideReport_ListofImagesAndFiles.ColumnFilename', 'Filename'), 
      'formatting' => function($value, $item) use ($linkBaseEditLink) { 
       return sprintf('<a href="%s">%s</a>', 
        Controller::join_links($linkBaseEditLink, $item->ID."/edit"), 
        strstr($value, '/assets/', false) 
       ); 
      } 
     ) 
    ); 

    return $fields; 
} 

我不知道这是不是有史以来最好的解决方案 - 它的作品,我不能找到与SilverStripe的这种报告创建相关的任何其他内容(我发现的所有内容都是为了获取Pages而不是图片或文件)

我不得不做一些调整,因为没有CMSFileEditController就像有一个CMSPageEditController,但我用我所得到的。

如果有人有更好的解决方案,那么请务必分享!