/** * Returns a field collection * * @param mixed $entity ElggEntity or an array of entity attributes * @param string $action Action name (used as a plugin hook type) * @param array $params Additional context params to pass to the hook * @return \hypeJunction\Prototyper\Elements\FieldCollection */ public function fields($entity = array(), $action = 'all', array $params = array()) { $fieldCollection = array(); $entity = $this->entityFactory->build($entity); if ($entity instanceof \ElggEntity) { $params['entity'] = $entity; $fields = (array) elgg_trigger_plugin_hook('prototype', $action, $params, array()); $attribute_names = $this->entityFactory->getAttributeNames($entity); if (!$entity->guid) { $fields['type'] = array('type' => 'hidden'); $fields['subtype'] = array('type' => 'hidden'); $fields['owner_guid'] = array('type' => 'hidden'); $fields['container_guid'] = array('type' => 'hidden'); } else { $fields['guid'] = array('type' => 'hidden'); } foreach ($fields as $shortname => $field) { $field['entity_type'] = $entity->getType(); $field['entity_subtype'] = $entity->getSubtype(); if (empty($field['shortname'])) { $field['shortname'] = $shortname; } if (in_array($shortname, $attribute_names)) { $field['data_type'] = 'attribute'; $field['class_name'] = Elements\AttributeField::CLASSNAME; } $fieldObj = $this->fieldFactory->build($field); if ($fieldObj instanceof Elements\Field) { $fieldCollection[] = $fieldObj; } } } return new Elements\FieldCollection($fieldCollection); }
/** * {@inheritdoc} */ public function resolve(array $fields) { $resolvedFields = []; foreach ($fields as $field) { $resolvedFields[] = $this->fieldFactory->create(['column' => $field]); } return $resolvedFields; }
function testPublisherIsAcceptedFromQueryString() { $factory = new FieldFactory(); $query_array = array('example_publisher' => 768); $field = $factory->newField('scope'); $field->setName('example'); $field->setValueFromArray($query_array); $scope = $field->getValue(); $publisher_id = $scope->getPublisherId(); $this->assertEqual($publisher_id, 768); }
function MAX_getDatesByPeriod($period, $period_start = 0, $period_end = 0) { require_once MAX_PATH . '/lib/max/Admin/UI/FieldFactory.php'; $oDaySpan =& FieldFactory::newField('day-span'); $oDaySpan->_name = 'period'; $oDaySpan->setValueFromArray(array('period_preset' => $period, 'period_start' => $period_start, 'period_end' => $period_end)); $dayBegin = $oDaySpan->getStartDate(); $dayEnd = $oDaySpan->getEndDate(); $aDates = array(); $aDates['day_begin'] = is_object($dayBegin) ? $dayBegin->format('%Y-%m-%d') : ''; $aDates['day_end'] = is_object($dayEnd) ? $dayEnd->format('%Y-%m-%d') : ''; return $aDates; }
/** * Retrieve field dependencies * * @param array $dependencies * @param string $storeCode * @param string $fieldPrefix * @return array */ public function getDependencies($dependencies, $storeCode, $fieldPrefix = '') { $output = []; foreach ($dependencies as $depend) { $field = $this->_fieldFactory->create(['fieldData' => $depend, 'fieldPrefix' => $fieldPrefix]); $shouldAddDependency = true; /** @var \Magento\Config\Model\Config\Structure\Element\Field $dependentField */ $dependentField = $this->_fieldLocator->getElement($depend['id']); /* * If dependent field can't be shown in current scope and real dependent config value * is not equal to preferred one, then hide dependence fields by adding dependence * based on not shown field (not rendered field) */ if (false == $dependentField->isVisible()) { $valueInStore = $this->_scopeConfig->getValue($dependentField->getPath($fieldPrefix), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeCode); $shouldAddDependency = !$field->isValueSatisfy($valueInStore); } if ($shouldAddDependency) { $output[$field->getId()] = $field; } } return $output; }
/** * A private method to display the report generation screen for a * report plugin to the UI. * * @access private * @param Plugins_Reports $oPlugin The plugin to display. * @param string $reportIdentifier The string identifying the report. * @param int $errorCode error code given by last report generation */ function _groupReportPluginGeneration($oPlugin, $reportIdentifier, $errorCode = null) { $aInfo = $oPlugin->info(); if (!empty($errorCode)) { $errorMessage = $oPlugin->getErrorMessage($errorCode); } // Print the report introduction $this->_displayReportIntroduction($aInfo['plugin-export'], $aInfo['plugin-name'], $aInfo['plugin-description'], $errorMessage); // Get the plugins generation parameter details if ($aPluginInfo = $aInfo['plugin-import']) { // Print the start of the report execution submission form $this->_displayParameterListHeader(); foreach ($aPluginInfo as $key => $aParameters) { // Print the report generation parameter $oField =& $this->oFieldFactory->newField($aParameters['type']); $oField->_name = $key; if (!is_null($aParameters['default'])) { $oField->setValue($aParameters['default']); } $oField->setValueFromArray($aParameters); if (!is_null($aParameters['field_selection_names'])) { $oField->_fieldSelectionNames = $aParameters['field_selection_names']; } if (!is_null($aParameters['size'])) { $oField->_size = $aParameters['size']; } if (!is_null($aParameters['filter'])) { $oField->setFilter($aParameters['filter']); } $this->_displayParameterBreak(); echo "<tr><td width='30'> </td><td>{$aParameters['title']}</td><td>"; $oField->_tabIndex = $this->tabindex; $oField->display(); $this->tabindex = $oField->_tabIndex; echo "</td></tr>"; } // Print a parameter break line $this->_displayParameterBreak(); // Print the end of the report execution submission form $this->_displayParameterListFooter($reportIdentifier); } // Print the closing table info $this->_displayReportInformationFooter(); }
/** * A private method to obtain the variables required for generating * the report from the $_GET array. * * @access private * @param array $aImport An array of the required variables for * the report. * @return array An array of the required variables. */ function _getVariablesForReport($aImport) { $aVariables = array(); foreach (array_keys($aImport) as $key) { $oField =& FieldFactory::newField($aImport[$key]['type']); $oField->_name = $key; $oField->setValueFromArray($_GET); $aVariables[] = $oField->_value; } return $aVariables; }
function testGenerateTextField() { $factory = new FieldFactory(); $field =& $factory->newField('edit'); $this->assertIsA($field, 'Admin_UI_TextField'); }
function MAX_displayDateSelectionForm($period, $period_start, $period_end, $pageName, &$tabindex, $hiddenValues = null) { global $tabindex; require_once MAX_PATH . '/lib/max/Admin/UI/FieldFactory.php'; $oDaySpan =& FieldFactory::newField('day-span'); $oDaySpan->_name = 'period'; $oDaySpan->_autoSubmit = true; $oDaySpan->setValueFromArray(array('period_preset' => $period, 'period_start' => $period_start, 'period_end' => $period_end)); $oDaySpan->_tabIndex = $tabindex; echo "\n <form id='period_form' name='period_form' action='{$pageName}'>"; $oDaySpan->display(); $tabindex = $oDaySpan->_tabIndex; echo "\n <input type='button' value='Go' onclick='return periodFormSubmit()' style='margin-left: 1em' tabindex='" . $tabindex++ . "' />"; _displayHiddenValues($hiddenValues); echo "\n </form>"; }
/** * A private method to initialise the day span selector element. * * @access pivate */ function _initDaySpanSelector() { require_once MAX_PATH . '/lib/max/Admin/UI/FieldFactory.php'; $aPeriod = array(); $aPeriod['period_preset'] = MAX_getStoredValue('period_preset', 'today'); $aPeriod['period_start'] = MAX_getStoredValue('period_start', date('Y-m-d')); $aPeriod['period_end'] = MAX_getStoredValue('period_end', date('Y-m-d')); $this->oDaySpanSelector =& FieldFactory::newField('day-span'); $this->oDaySpanSelector->_name = 'period'; $this->oDaySpanSelector->enableAutoSubmit(); $this->oDaySpanSelector->setValueFromArray($aPeriod); $this->aDates = array('day_begin' => $this->oDaySpanSelector->getStartDate(), 'day_end' => $this->oDaySpanSelector->getEndDate()); if (!is_null($this->aDates['day_begin'])) { $this->aDates['day_begin'] = $this->aDates['day_begin']->format('%Y-%m-%d'); $this->aDates['day_end'] = $this->aDates['day_end']->format('%Y-%m-%d'); } else { $this->aDates = array(); } $this->aGlobalPrefs['period_preset'] = $this->oDaySpanSelector->_fieldSelectionValue; $this->aGlobalPrefs['period_start'] = $this->aDates['day_begin']; $this->aGlobalPrefs['period_end'] = $this->aDates['day_end']; }
/** * Will test if the field factory reacts on wrong positions properly * * @return null * * @covers AppserverIo\Microcron\FieldFactory::getField * * @expectedException \InvalidArgumentException */ public function testValidatesFieldPosition() { $f = new FieldFactory(); $f->getField(-1); }