Created
June 25, 2018 10:01
-
-
Save joseph-montanez/a05961fbbd0d745277535709f11313e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Ui\TableColumn; | |
class Link extends \atk4\ui\TableColumn\Link | |
{ | |
/** | |
* Return a URL string from a callable | |
* | |
* @var callable $cb | |
*/ | |
public $cb; | |
public function __construct($page = null, $args = [], $cb = null) | |
{ | |
if (is_array($page)) { | |
$page = ['page' => $page]; | |
} elseif (is_string($page)) { | |
$page = ['url' => $page]; | |
} | |
if ($args) { | |
$page['args'] = $args; | |
} | |
if (is_callable($cb)) { | |
$this->cb = $cb; | |
} | |
parent::__construct($page); | |
} | |
public function getHTMLTags($row, $field) | |
{ | |
if (is_callable($this->cb)) { | |
return ['c_'.$this->short_name => call_user_func($this->cb, $row->get())]; | |
} | |
// Decide on the content | |
if ($this->url) { | |
return ['c_'.$this->short_name => $this->url->set($row->get())->render()]; | |
} | |
$p = $this->page ?: []; | |
foreach ($this->args as $key => $val) { | |
if (is_numeric($key)) { | |
$key = $val; | |
} | |
if ($row->hasElement($val)) { | |
$p[$key] = $row[$val]; | |
} | |
} | |
return ['c_'.$this->short_name => $this->table->url($p)]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment