/**
  * Create a field object, configured to render a checkbox for use in selecting
  * items for the supplied BulkActions object.
  *
  * @param BulkActions $bulkActions
  * @param TableCellHelper $renderer
  * @return Field
  * @throws Exception
  */
 public function direct(BulkActions $bulkActions, TableCellHelper $renderer)
 {
     $field = new Field();
     $key = $bulkActions->getPrimaryKey()->getName();
     $field->setId($bulkActions->getId())->setVisible(true);
     $renderer->getHeaderRenderer()->assign($bulkActions->getId(), function () {
         return '';
     });
     $renderer->getContentRenderer()->assign($bulkActions->getId(), function ($helper, array $rowData) use($bulkActions, $key) {
         /* @var $helper \Dewdrop\Fields\Helper\TableCell\Content */
         if (!isset($rowData[$key])) {
             throw new Exception("{$key} not available in row data for bulk action checkbox render.");
         }
         $value = $rowData[$key];
         return sprintf('<input class="bulk-checkbox" type="checkbox" name="%s[]" value="%s" %s />', $helper->getView()->escapeHtmlAttr($bulkActions->getId()), $helper->getView()->escapeHtmlAttr($value), in_array($value, $bulkActions->getSelected()) ? 'checked="checked"' : '');
     });
     return $field;
 }
Ejemplo n.º 2
0
 /**
  * Button actions are processed when the submit input is available in POST.
  *
  * @return bool
  */
 public function shouldProcess()
 {
     return $this->bulkActions->getRequest()->isPost() && $this->bulkActions->getRequest()->getPost($this->id);
 }
Ejemplo n.º 3
0
 public function testCanUseCustomInputId()
 {
     $request = new Request(['fafafafa' => [], 'fafafafa_check_pages' => 1]);
     $listing = $this->createListingWithRequest($request);
     $bulkActions = new BulkActions($listing, $this->fields);
     $bulkActions->setId('fafafafa');
     $this->assertEquals('fafafafa', $bulkActions->getId());
     $action = $this->getMock('\\Dewdrop\\Fields\\Listing\\BulkActions\\ActionInterface', array('shouldProcess', 'process', 'render'), array($bulkActions));
     $bulkActions->add($action);
     $action->expects($this->once())->method('shouldProcess')->will($this->returnValue(true));
     $action->expects($this->once())->method('process')->with([1, 2, 3, 4, 5]);
     $bulkActions->process();
 }