Updated I fixed the preprocess_html hook as adviced, and added a pic of the structure of the module, maybe is something wrong there??
I just created a custom module for drupal-8 that ad a customizable block. Very simple, is currently working but now i want to add some look to the content of the block.
So my last attempt to achieve this was adding a libraries.yml to the module linking the block_header.css file and at the render array i added #prefix and #suffix with the css tags (div class='foo').
The code doesn't give me any error but it's not applying the font-weight of the css file.
Could you point me to the right direction?
This are the files:
block_header.libraries.yml
block_header:
version: 1.x
css:
theme:
css/block_header.css: {}
BlockHeader.php
<?php
namespace Drupal\block_header\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'Header' Block.
*
* #Block(
* id = "block_header",
* admin_label = #Translation("Block Header"),
* category = #Translation("Block Header"),
* )
*/
class BlockHeader extends BlockBase implements BlockPluginInterface {
function block_header_preprocess_html(&$variables) {
$variables['page']['#attached']['library'][] = 'Fussion_Modules/block_header/block_header';
}
/**
* {#inheritdoc}
*/
public function build() {
$config = $this->getConfiguration();
if (!empty($config['block_header_title']) && ($config['block_header_text'])) {
$title = $config['block_header_title'];
$descp = $config['block_header_text'];
}
else {
$title = $this->t('<div>Atención! Titulo no configurado!</div> </p>');
$descp = $this->t('<div>Atención! Descripción no configurada!</div>');
}
$block = array
(
'title' => array
(
'#prefix' => '<div class="title"><p>',
'#suffix' => '</p></div>',
'#markup' => t('#title', array('#title' => $title,)),
),
'description' => array
(
'#prefix' => '<div class="descp"><p>',
'#suffix' => '</p></div>',
'#markup' => t('#descp', array('#descp' => $descp,))
),
);
return $block;
}
/**
* {#inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->getConfiguration();
$form['block_header_title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Titulo del Bloque'),
'#description' => $this->t('Titulo del Bloque'),
'#default_value' => isset($config['block_header_title']) ? $config['block_header_title'] : '',
);
$form['block_header_text'] = array(
'#type' => 'textarea',
'#title' => $this->t('Descripción'),
'#description' => $this->t('Descripción del bloque'),
'#default_value' => isset($config['block_header_text']) ? $config['block_header_text'] : '',
);
return $form;
}
/**
* {#inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$values = $form_state->getValues();
$this->configuration['block_header_title'] = $values['block_header_title'];
$this->configuration['block_header_text'] = $values['block_header_text'];
$this->configuration['block_header_title'] = $form_state->getValue('block_header_title');
$this->configuration['block_header_text'] = $form_state->getValue('block_header_text');
}
}
block_header.css
.title{
font-weight: 500;
color:darkblue;
}
This is my module structure
Any ideas what i'm doing wrong?
Try updating your $block array that is being returned and remove the preprocess function:
$block = array
(
'title' => array
(
'#prefix' => '<div class="title"><p>',
'#suffix' => '</p></div>',
'#markup' => t('#title', array('#title' => $title,)),
),
'description' => array
(
'#prefix' => '<div class="descp"><p>',
'#suffix' => '</p></div>',
'#markup' => t('#descp', array('#descp' => $descp,))
),
'#attached' => array
(
'library' => array
(
'block_header/block_header'
)
)
);
An alternative following the advice on this page at drupal.org is to attach the css file in the build array of the block. So in block_header.libraries.yml you could write
block_header.tree:
css:
theme:
css/block_header.css: {}
And in BlockHeader.php
public function build() {
[...]
block = array (
'#attached' => array(
'library' => array(
'block_header/block_header.tree',
),
),
[...]
),
}
One way to do it is to:
Add libraries to block_header.info.yml file in your module:
libraries:
- block_header/block_header
Create block_header.libraries.yml file and add:
block_header:
version: 1.x
css:
module:
css/block_header.css: {}
Place css file you want to attach to css/block_header.css
Include css to custom form statement
Place the following line in form building part of the module:$form['#attached']['library'][] = 'block_header/block_header';
Rewrite following function in module file
function block_header_preprocess_html(&$variables) { $variables['page']['#attached']['library'][] = 'block_header/block_header'; }
So, i finally found the problem. The HOOK i was trying to implement to attach the *.css file it's need to be at the *.module file, wich i didn't had.
So i created the block_header.module with this HOOK:
<?php
/**
* Implements hook_preprocess_HOOK()
*/
function block_header_preprocess_block(&$variables) {
if ($variables['plugin_id'] == 'block_header') {
$variables['#attached']['library'][] = 'block_header/block_header';
}
}
After that i just deleted the HOOK i was using, so the final versión of the BlockHeader.php is:
<?php
namespace Drupal\block_header\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'Header' Block.
*
* #Block(
* id = "block_header",
* admin_label = #Translation("Block Header"),
* category = #Translation("Block Header"),
* )
*/
class BlockHeader extends BlockBase implements BlockPluginInterface {
/**
* {#inheritdoc}
*/
public function build() {
$config = $this->getConfiguration();
if (!empty($config['block_header_title']) && ($config['block_header_text'])) {
$title = $config['block_header_title'];
$descp = $config['block_header_text'];
}
else {
$title = $this->t('<div>Atención! Titulo no configurado!</div> </p>');
$descp = $this->t('<div>Atención! Descripción no configurada!</div>');
}
$block = array
(
'title' => array
(
'#prefix' => '<div class="title"><p>', /* HERE I ADD THE CSS TAGS */
'#suffix' => '</p></div>',
'#markup' => t('#title', array('#title' => $title,)),
),
'description' => array
(
'#prefix' => '<div class="descp"><p>', /* HERE I ADD THE CSS TAGS */
'#suffix' => '</p></div>',
'#markup' => t('#descp', array('#descp' => $descp,))
),
);
return $block;
}
/**
* {#inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->getConfiguration();
$form['block_header_title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Titulo del Bloque'),
'#description' => $this->t('Titulo del Bloque'),
'#default_value' => isset($config['block_header_title']) ? $config['block_header_title'] : '',
);
$form['block_header_text'] = array(
'#type' => 'textarea',
'#title' => $this->t('Descripción'),
'#description' => $this->t('Descripción del bloque'),
'#default_value' => isset($config['block_header_text']) ? $config['block_header_text'] : '',
);
return $form;
}
/**
* {#inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$values = $form_state->getValues();
$this->configuration['block_header_title'] = $values['block_header_title'];
$this->configuration['block_header_text'] = $values['block_header_text'];
$this->configuration['block_header_title'] = $form_state->getValue('block_header_title');
$this->configuration['block_header_text'] = $form_state->getValue('block_header_text');
}
}
And that's it, now i'm getting the *.css file i created applied to the block created by the module.
Special thanks to #No Sssweat
Related
Please consider the following php class extends the WP_REST_Controller class of Wordpress related to Rest API:
<?php
class MCQAcademy_Endpoint extends WP_REST_Controller {
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
$version = '1';
$namespace = 'custompath/v' . $version;
$base = 'endpointbase';
register_rest_route(
$namespace,
'/' . $base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => array(),
)
)
);
}
/**
*
*/
public function get_items( $request ) {
$rs = array(
'data' => array(),
'request' => array(
'lang' => 'en',
),
);
$args = array();
$items = get_posts( $args );
foreach( $items as $item ) {
$itemdata = $this->prepare_item_for_response( $item, $request );
$rs['data'][] = $this->prepare_response_for_collection( $itemdata );
}
$rs['wp_get_current_user'] = wp_get_current_user(); // Does not output as expected
return new WP_REST_Response( $rs, 200 );
}
/**
* Check if a given request has access to get items
*/
public function get_items_permissions_check( $request ) {
return true; // to make readable by all
}
/**
* Prepare the item for create or update operation
*/
protected function prepare_item_for_database( $request ) {
return $request;
}
/**
* Prepare the item for the REST response
*/
public function prepare_item_for_response( $item, $request ) {
$data = array(
'ID' => $item->ID,
'post_content' => wpautop($item->post_content),
'post_title' => $item->post_title,
);
return $data;
}
/**
* Get the query params for collections
*/
public function get_collection_params() {
return array(
'page' => array(
'description' => 'Current page of the collection.',
'type' => 'integer',
'default' => 1,
'sanitize_callback' => 'absint',
),
'per_page' => array(
'description' => 'Maximum number of items to be returned in result set.',
'type' => 'integer',
'default' => 10,
'sanitize_callback' => 'absint',
),
'search' => array(
'description' => 'Limit results to those matching a string.',
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
),
);
}
// Register our REST Server
public function hook_rest_server(){
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
}
$myEndpoint = new MCQAcademy_Endpoint();
$myEndpoint->hook_rest_server();
Everything is going well except calling the wp_get_current_user() function in the get_items() function return empty user even though the user is loggedin in the website.
What is the solution to get the loggedin user info in Rest API endpoint function?
I am trying to create my first drupal 8 module. in this module I have to create a new form and provide user a file uploading capability in this form. here is my form controller:
class Make2d extends FormBase {
/**
* {#inheritdoc}
*/
public function getFormId() {
return 'make2d_form';
}
/**
* {#inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if (\Drupal::currentUser()->isAnonymous()) {
return new RedirectResponse(\Drupal::url('user.page'));
}
$form['sheet_size'] = array(
'#type' => 'radios',
'#title' => t('Sheet Size'),
'#options' => array(t('10 X 10(2.99$)'), t('17 X 17(4.99$)'), t('28 X 28(5.99$)')),
);
$form['uploaded_file'] = array(
'#type' => 'file',
'#title' => t('Upload your file'),
'#required' => true
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Save to Cart'),
'#button_type' => 'primary',
);
return $form;
}
/**
* {#inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
echo '<pre>';
print_r($form_state->getvalues());
echo '</pre>';
}
/**
* {#inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
print_r($form_state['values']);
}
}
this is the result when I go to my form's page:
image of my form
then I choose a file from my computer and submit the form. but when I print_r my $form_state->getvalues() array the result is sth like this:
Array
(
[sheet_size] => 0
[uploaded_file] =>
[submit] => Drupal\Core\StringTranslation\TranslatableMarkup Object
...
you can see that [uploaded_file] is empty. and there is an error on top of the form about uploading a file. what is wrong with the form controller and file uploading.
thanks.
at last! I find it. we should use '#type' = 'managed_file' so that we let drupal to manage uploaded file. in the case we use '#type' = 'file' we must transfer file ourselves by file_save_upload().
hi i was wondering on how to show order summary in paypal with JMSPaymentPaypalBundle ?!
ay tips will be greatly appreciated ..
here is my paypalController code in case needed
<?php
namespace Splurgin\EventsBundle\Controller;
use JMS\DiExtraBundle\Annotation as DI;
use JMS\Payment\CoreBundle\Entity\Payment;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
class PaymentController
{
/** #DI\Inject */
private $request;
/** #DI\Inject */
private $router;
/** #DI\Inject("doctrine.orm.entity_manager") */
private $em;
/** #DI\Inject("payment.plugin_controller") */
private $ppc;
/**
* #DI\Inject("service_container")
*
*/
private $container;
/**
* #Template
*/
public function detailsAction($package)
{
// note this ticket at this point in inactive ...
$order = $this->container->get('ticket')->generateTicket($package);
$order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order);
$packageId = $order->getPackageId();
$package = $this->em->getRepository('SplurginEventsBundle:SplurginEventPackages')->find($package);
$price = $package->getPrice();
var_dump($price);
if($price == null){
throw new \RuntimeException('Package was not found: '.$result->getReasonCode());
}
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $price,
'currency' => 'USD',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->router->generate('payment_complete', array(
'order' => $order->getId(),
), true),
'cancel_url' => $this->router->generate('payment_cancel', array(
'order' => $order->getId(),
), true)
),
),
));
if ('POST' === $this->request->getMethod()) {
$form->bindRequest($this->request);
if ($form->isValid()) {
$this->ppc->createPaymentInstruction($instruction = $form->getData());
$order->setPaymentInstruction($instruction);
$this->em->persist($order);
$this->em->flush($order);
return new RedirectResponse($this->router->generate('payment_complete', array(
'order' => $order->getId(),
)));
}
}
return array(
'form' => $form->createView(),
'order'=>$order->getId(),
);
}
/** #DI\LookupMethod("form.factory") */
protected function getFormFactory() { }
/**
*/
public function completeAction($order)
{
$order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order);
$instruction = $order->getPaymentInstruction();
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}
$result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();
if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();
if ($action instanceof VisitUrl) {
return new RedirectResponse($action->getUrl());
}
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}
}
public function cancelAction($order)
{
die('cancel the payment');
}
}
i really dont know why this is not a part of the docs , but the bundle is capable of setting checkout parameters out of the box ...
here is how i have done it
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $price,
'currency' => 'USD',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->router->generate('payment_complete', array(
'order' => $order->getId(),
), true),
'cancel_url' => $this->router->generate('payment_cancel', array(
'order' => $order->getId(),
), true),
'checkout_params' => array(
'L_PAYMENTREQUEST_0_NAME0' => 'event',
'L_PAYMENTREQUEST_0_DESC0' => 'some event that the user is trying to buy',
'L_PAYMENTREQUEST_0_AMT0'=> 6.00, // if you get 10413 , then visit the api errors documentation , this number should be the total amount (usually the same as the price )
// 'L_PAYMENTREQUEST_0_ITEMCATEGORY0'=> 'Digital',
),
),
),
));
error code can be found here
SetExpressCheckout Request Fields here
i will provide a pull request to the documentation as soon as i can .. :)
I'm trying to create a new custom field formatter for text fields but nothing is showing at all.
I tried un-installing and re-installing the module and flushed the cache many times, and nothing worked.
Here's the code I used
/**
* Implementation of hook_field_formatter_info()
*/
function facebooklink_field_formatter_info()
{
return array(
'cfieldformatter_text_1' => array(
'label' => t('Text 1'),
'field types' => array('text', 'text_long', 'text_with_summary'),
'settings' => array(
'pic_size' => 'small',
'tooltip' => 'Link to user Facebook page',
),
),
);
}
/**
* Implementation of hook_field_formatter_settings_form()
*/
function facebooklink_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state)
{
//This gets the view_mode where our settings are stored
$display = $instance['display'][$view_mode];
//This gets the actual settings
$settings = $display['settings'];
//Initialize the element variable
$element = array();
$element['pic_size'] = array(
'#type' => 'select', // Use a select box widget
'#title' => t('Button Size'), // Widget label
'#description' => t('Select what size of FB button'), // Helper text
'#default_value' => $settings['pic_size'], // Get the value if it's already been set
'#options' => array(
'small' => 'Small',
'medium' => 'Medium',
'large' => 'Large',
),
);
$element['tooltip'] = array(
'#type' => 'textfield', // Use a textbox
'#title' => t('Tool Tip'), // Widget label
'#description' => t('This text will appear when a user mouses over.'), // helper text
'#default_value' => $settings['tooltip'], // Get the value if it's already been set
);
return $element;
}
/**
* Implementation of hook_field_formatter_settings_summary()
*/
function facebooklink_field_formatter_settings_summary($field, $instance, $view_mode)
{
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = t('Use a #size Facebook button with the tooltip of "#tooltip"', array(
'#size' => $settings['pic_size'],
'#tooltip' => $settings['tooltip'],
));
return $summary;
}
/**
* Implementation of hook_field_formatter_view()
*/
function facebooklink_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)
{
$element = array(); // Initialize the var
$settings = $display['settings']; // get the settings
$size = $settings['pic_size']; // The Size setting selected in the settings form
$tooltip = $settings['tooltip']; // The tool tip assigned in settings
// Create the image - Note that I'm storing the images in our module but they could be anywhere
$image = '<img src="/' . drupal_get_path('module', 'facebooklink') . 'fb-' . $size . '.png">';
foreach ($items as $delta => $item) {
$fb = $item['safe_value']; // Getting the actual value
}
$options = array(
'html' => TRUE, // This tells Drupal that we're sending HTML, not plain text, otherwise it would encode it
'attributes' => array(
'title' => $tooltip, // This sets our tooltip
),
);
if(isset($fb)) {
$link = l($image, $fb, $options); // Create the Link
$element[0]['#markup'] = $link; // Assign it to the #markup of the element
}
return $element;
}
Any help with this crazy issue?!!!.
I would suggest you either name your formatter 'facebooklink' instead 'cfieldformatter_text_1' in hook_field_formatter_info (this works when you have one single formatter in a module) or explicity trigger the formatter in hook_field_formatter_view as below:
/**
* Implementation of hook_field_formatter_view()
*/
function facebooklink_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)
{
$element = array(); // Initialize the var
$settings = $display['settings']; // get the settings
switch ($display['type']) {
case 'cfieldformatter_text_1':
$size = $settings['pic_size']; // The Size setting selected in the settings form
$tooltip = $settings['tooltip']; // The tool tip assigned in settings
// Create the image - Note that I'm storing the images in our module but they could be anywhere
$image = '<img src="/' . drupal_get_path('module', 'facebooklink') . 'fb-' . $size . '.png">';
foreach ($items as $delta => $item) {
$fb = $item['safe_value']; // Getting the actual value
}
$options = array(
'html' => TRUE, // This tells Drupal that we're sending HTML, not plain text, otherwise it would encode it
'attributes' => array(
'title' => $tooltip, // This sets our tooltip
),
);
if(isset($fb)) {
$link = l($image, $fb, $options); // Create the Link
$element[0]['#markup'] = $link; // Assign it to the #markup of the element
}
break;
}
return $element;
}
I'm building a module (my_module) in Drupal 7.
It has some functionality and also will create new content type.
In my_module.install I implemented the hook_install (my_module_install).
Can I use more one implementation of hook_install to create new content type (my_cck_install) in this module?
If (yes), how should I do this?
Else: have I do this in another module? :-)
You can't use more than one implementation of hook_install in the same module; in PHP you can't have 2 function with the same name which rules this out.
You would just need to add your new content type in the same hook_install anyway (have a look at how the standard installation profile does it at /profiles/standard/standard.install). This is how I always add new content types from the install file (using the example of a testimonials module):
function testimonial_install() {
// Make sure a testimonial content type doesn't already exist
if (!in_array('testimonial', node_type_get_names())) {
$type = array(
'type' => 'testimonial',
'name' => st('Testimonial'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'title_label' => 'Customer / Client Name'
);
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
}
The following code will create a content type called "Event" with a machine name of 'event' and a title field -
//CREATE NEW CONTENT TYPE
function orderform_node_info() {
return array(
'event' => array(
'name' => t('Event'),
'base' => 'event',
'description' => t('A event content type'),
'has_title' => TRUE
),
);
}
function event_form($node,$form_state) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('event Title'),
'#default_value' => !empty($node->title) ? $node->title : '',
'#required' => TRUE,
'#weight' => -5
);
return $form;
}
//END CONTENT TYPE
you should place it in your .module file... if you want do add additional fields to it, let me know and I'll patch you up with the code... good luck!
/**
* Implements hook_node_info()
*/
function mymodule_node_info() {
return array(
'news' => array(
'name' => t('News'),
'base' => 'news',
'description' => t('You can add News here'),
'has_title' => TRUE,
'title_label' => t('News title')
)
);
}
/**
* Implement hook_form()
*/
function mymodule_form($node, $form_state) {
return node_content_form($node, $form_state);
}
Add the implementation to mymodule.install is as follows:
/**
* Implements hook_install().
*/
function mymodule_install() {
node_types_rebuild();
$types = node_type_get_types();|
node_add_body_field($types['news']);
}
You can get a detailed description with code from here
/*
* Implementation in hook node info in .Module file
*/
function test_node_info() {
return array(
'product' => array(
'name' => t('Product'),
'base' => 'product',
'description' => t('Product Title'),
)
);
}
/**
* Implement hook_form()
*/
function product_form($node, $form_state) {
return node_content_form($node, $form_state);
}
/**
* Implements hook_install() in .install file.
*/
function test_install() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['product']);
//New way to implement to add fields in your content type
foreach (_test_installed_fields() as $field) {
field_create_field($field);
}
foreach (_test_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'product';
field_create_instance($fieldinstance);
}
}
/*
* Define your fields
*/
function _test_installed_fields() {
$t = get_t();
return array(
'product_title123' => array(
'field_name' => 'product_title123',
'label' => $t('Product Title'),
'type' => 'text'
),
'description123' => array(
'field_name' => 'description123',
'label' => $t('Description'),
'type' => 'text'
),
);
}
/*
* Define your instance of fields
*/
function _test_installed_instances() {
$t = get_t();
return array(
'product_title123' => array(
'field_name' => 'product_title123',
'type' => 'text',
'label' => $t('Product Title'),
'widget' => array(
'type' => 'text_textfield'
),
'display' => array(
'example_node_list' => array(
'label' => $t('Product Title'),
'type' => 'text'
)
)
),
'description123' => array(
'field_name' => 'description123',
'type' => 'text',
'label' => $t('Description'),
'widget' => array(
'type' => 'text_textarea_with_summary'
),
'display' => array(
'example_node_list' => array(
'label' => $t('Description'),
'type' => 'text'
)
)
),
);
}
/**
* Implements hook_uninstall().
*/
function test_uninstall() {
$ournewtype = 'product';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $ournewtype));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
node_type_delete($ournewtype);
}
That's it.