/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$fblikebutton_node_options = node_type_get_names();
$config = $this->config('fblikebutton.settings');
$form['fblikebutton_dynamic_visibility'] = array('#type' => 'details', '#title' => $this->t('Visibility settings'), '#open' => TRUE);
$form['fblikebutton_dynamic_visibility']['fblikebutton_node_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Display the Like button on these content types:'), '#options' => $fblikebutton_node_options, '#default_value' => $config->get('node_types'), '#description' => $this->t('Each of these content types will have the "like" button automatically added to them.'));
/**
* @TODO: Uncomment this when the module is also able to add the button to
* the links area
*
$form['fblikebutton_dynamic_visibility']['fblikebutton_full_node_display'] = array(
'#type' => 'radios',
'#title' => $this->t('Where do you want to show the Like button (full node view)?'),
'#options' => array(
$this->t('Content area'),
$this->t('Links area')
),
'#default_value' => $config->get('full_node_display'),
'#description' => $this->t('If <em>Content area</em> is selected, the button will appear in the same area as the node content. When you select <em>Links area</em> the Like button will be visible in the links area, usually at the bottom of the node (When you select this last option you may want to adjust the Appearance settings). You can also configure Static Like Button Blocks in'. \Drupal::l($this->t('block page'), Url::fromRoute('block.admin_display')) . '.'),
);
*/
$form['fblikebutton_dynamic_visibility']['fblikebutton_teaser_display'] = array('#type' => 'radios', '#title' => $this->t('Where do you want to show the Like button on teasers?'), '#options' => array($this->t('Don\'t show on teasers'), $this->t('Content area')), '#default_value' => $config->get('teaser_display'), '#description' => $this->t('If you want to show the like button on teasers you can select the display area.'));
$form['fblikebutton_dynamic_appearance'] = array('#type' => 'details', '#title' => $this->t('Appearance settings'), '#open' => TRUE);
$form['fblikebutton_dynamic_appearance']['fblikebutton_layout'] = array('#type' => 'select', '#title' => $this->t('Layout style'), '#options' => array('standard' => $this->t('Standard'), 'box_count' => $this->t('Box Count'), 'button_count' => $this->t('Button Count'), 'button' => $this->t('Button')), '#default_value' => $config->get('layout'), '#description' => $this->t('Determines the size and amount of social context next to the button.'));
// The actial values passed in from the options will be converted to a boolean
// in the validation function, so it doesn't really matter what we use.
$form['fblikebutton_dynamic_appearance']['fblikebutton_show_faces'] = array('#type' => 'select', '#title' => $this->t('Show faces in the box?'), '#options' => array(t('Do not show faces'), $this->t('Show faces')), '#default_value' => $config->get('show_faces', TRUE), '#description' => $this->t('Show profile pictures below the button. Only works if <em>Layout style</em> (found above) is set to <em>Standard</em> (otherwise, value is ignored).'));
$form['fblikebutton_dynamic_appearance']['fblikebutton_action'] = array('#type' => 'select', '#title' => $this->t('Verb to display'), '#options' => array('like' => $this->t('Like'), 'recommend' => $this->t('Recommend')), '#default_value' => $config->get('action'), '#description' => $this->t('The verbiage to display inside the button itself.'));
$form['fblikebutton_dynamic_appearance']['fblikebutton_font'] = array('#type' => 'select', '#title' => $this->t('Font'), '#options' => array('arial' => 'Arial', 'lucida+grande' => 'Lucida Grande', 'segoe+ui' => 'Segoe UI', 'tahoma' => 'Tahoma', 'trebuchet+ms' => 'Trebuchet MS', 'verdana' => 'Verdana'), '#default_value' => $config->get('font', 'arial'), '#description' => $this->t('The font with which to display the text of the button.'));
$form['fblikebutton_dynamic_appearance']['fblikebutton_color_scheme'] = array('#type' => 'select', '#title' => $this->t('Color scheme'), '#options' => array('light' => $this->t('Light'), 'dark' => $this->t('Dark')), '#default_value' => $config->get('color_scheme'), '#description' => $this->t('The color scheme of the box environtment.'));
$form['fblikebutton_dynamic_appearance']['fblikebutton_weight'] = array('#type' => 'number', '#title' => $this->t('Weight'), '#default_value' => $config->get('weight'), '#description' => $this->t('The weight determines where, at the content block, the like button will appear. The larger the weight, the lower it will appear on the node. For example, if you want the button to appear more toward the top of the node, choose <em>-40</em> as opposed to <em>-39, -38, 0, 1,</em> or <em>50,</em> etc. To position the Like button in its own block, go to the ' . \Drupal::l($this->t('block page'), Url::fromRoute('block.admin_display')) . '.'));
$form['fblikebutton_dynamic_appearance']['fblikebutton_language'] = array('#type' => 'textfield', '#title' => $this->t('Language'), '#default_value' => $config->get('language'), '#description' => $this->t('Specific language to use. Default is English. Examples:<br />French (France): <em>fr_FR</em><br />French (Canada): <em>fr_CA</em><br />More information can be found at http://developers.facebook.com/docs/internationalization/ and a full XML list can be found at http://www.facebook.com/translations/FacebookLocales.xml'));
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = parent::buildForm($form, $form_state);
$rate = $this->entity;
$form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('This name will appear to the customer when this tax is applied to an order.'), '#default_value' => $rate->label(), '#required' => TRUE);
$form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $rate->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'));
$form['rate'] = array('#type' => 'textfield', '#title' => $this->t('Rate'), '#description' => $this->t('The tax rate as a percent or decimal. Examples: 6%, .06'), '#size' => 15, '#default_value' => (double) $rate->getRate() * 100.0 . '%', '#required' => TRUE);
$form['jurisdiction'] = array('#type' => 'textfield', '#title' => $this->t('Jurisdiction'), '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), '#default_value' => $rate->getJurisdiction(), '#required' => FALSE);
$form['shippable'] = array('#type' => 'radios', '#title' => $this->t('Taxed products'), '#options' => array(0 => $this->t('Apply tax to any product regardless of its shippability.'), 1 => $this->t('Apply tax to shippable products only.')), '#default_value' => (int) $rate->isForShippable());
// TODO: Remove the need for a special case for product kit module.
$options = array();
foreach (node_type_get_names() as $type => $name) {
if ($type != 'product_kit' && uc_product_is_product($type)) {
$options[$type] = $name;
}
}
$options['blank-line'] = $this->t('"Blank line" product');
$form['product_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed product types'), '#description' => $this->t('Apply taxes to the specified product types/classes.'), '#default_value' => $rate->getProductTypes(), '#options' => $options);
$options = array();
foreach (_uc_line_item_list() as $id => $line_item) {
if (!in_array($id, ['subtotal', 'tax_subtotal', 'total', 'tax_display'])) {
$options[$id] = $line_item['title'];
}
}
$form['line_item_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed line items'), '#description' => $this->t('Adds the checked line item types to the total before applying this tax.'), '#default_value' => $rate->getLineItemTypes(), '#options' => $options);
$form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#description' => $this->t('Taxes are sorted by weight and then applied to the order sequentially. This value is important when taxes need to include other tax line items.'), '#default_value' => $rate->getWeight());
$form['display_include'] = array('#type' => 'checkbox', '#title' => $this->t('Include this tax when displaying product prices.'), '#default_value' => $rate->isIncludedInPrice());
$form['inclusion_text'] = array('#type' => 'textfield', '#title' => $this->t('Tax inclusion text'), '#description' => $this->t('This text will be displayed near the price to indicate that it includes tax.'), '#default_value' => $rate->getInclusionText());
return $form;
}
/**
* Ensures that node type functions (node_type_get_*) work correctly.
*
* Load available node types and validate the returned data.
*/
function testNodeTypeGetFunctions()
{
$node_types = node_type_get_types();
$node_names = node_type_get_names();
$this->assertTrue(isset($node_types['article']), 'Node type article is available.');
$this->assertTrue(isset($node_types['page']), 'Node type basic page is available.');
$this->assertEqual($node_types['article']->name, $node_names['article'], 'Correct node type base has been returned.');
$article = entity_load('node_type', 'article');
$this->assertEqual($node_types['article'], $article, 'Correct node type has been returned.');
$this->assertEqual($node_types['article']->name, $article->label(), 'Correct node type name has been returned.');
}
public function hook_page_alter(&$page)
{
// Add an extra "Panelizer" action on the content types admin page.
if ($_GET['q'] == 'admin/structure/types') {
// This only works with some themes.
if (!empty($page['content']['system_main']['node_table'])) {
// Shortcut.
$table =& $page['content']['system_main']['node_table'];
// Operations column should always be the last column in header.
// Increase its colspan by one to include possible panelizer link.
$operationsCol = end($table['#header']);
if (!empty($operationsCol['colspan'])) {
$operationsColKey = key($table['#header']);
$table['#header'][$operationsColKey]['colspan']++;
}
// Since we can't tell what row a type is for, but we know that they
// were generated in this order, go through the original types list.
$types = node_type_get_types();
$names = node_type_get_names();
$row_index = 0;
foreach ($names as $bundle => $name) {
$type = $types[$bundle];
if (node_hook($type->type, 'form')) {
$type_url_str = str_replace('_', '-', $type->type);
if ($this->is_panelized($bundle) && panelizer_administer_entity_bundle($this, $bundle)) {
$table['#rows'][$row_index][] = array('data' => l(t('panelizer'), 'admin/structure/types/manage/' . $type_url_str . '/panelizer'));
} else {
$table['#rows'][$row_index][] = array('data' => '');
}
// Update row index for next pass.
$row_index++;
}
}
}
}
}
/**
* Inform the Field API about one or more fieldable types.
*
* Inform the Field API about one or more fieldable types, (object
* types to which fields can be attached).
*
* @return
* An array whose keys are fieldable object type names and
* whose values identify properties of those types that the Field
* system needs to know about:
*
* name: The human-readable name of the type.
* id key: The object property that contains the primary id for the
* object. Every object passed to the Field API must
* have this property and its value must be numeric.
* revision key: The object property that contains the revision id
* for the object, or NULL if the object type is not
* versioned. The Field API assumes that all revision ids are
* unique across all instances of a type; this means, for example,
* that every object's revision ids cannot be 0, 1, 2, ...
* bundle key: The object property that contains the bundle name for
* the object (bundle name is what nodes call "content type").
* The bundle name defines which fields are connected to the object.
* cacheable: A boolean indicating whether Field API should cache
* loaded fields for each object, reducing the cost of
* field_attach_load().
* bundles: An array of all existing bundle names for this object
* type. TODO: Define format. TODO: I'm unclear why we need
* this.
*/
function hook_fieldable_info()
{
$return = array('node' => array('name' => t('Node'), 'id key' => 'nid', 'revision key' => 'vid', 'bundle key' => 'type', 'cacheable' => FALSE, 'bundles' => node_type_get_names()));
return $return;
}
请发表评论